ASP.NET Tutorial 4- How to Create a Login website - Connecting Database to Registration Page
Вставка
- Опубліковано 6 лют 2025
- ASP.NET Database Connection.ASP.NET Web Forms Database
How to connect asp.net to a database.
★★★Top Online Courses From ProgrammingKnowledge ★★★
Python Programming Course ➡️ bit.ly/2vsuMaS ⚫️ bit.ly/2GOaeQB
Java Programming Course ➡️ bit.ly/2GEfQMf ⚫️ bit.ly/2Vvjy4a
Bash Shell Scripting Course ➡️ bit.ly/2DBVF0C ⚫️ bit.ly/2UM06vF
Linux Command Line Tutorials ➡️ bit.ly/2IXuil0 ⚫️ bit.ly/2IXukt8
C Programming Course ➡️ bit.ly/2GQCiD1 ⚫️ bit.ly/2ZGN6ej
C++ Programming Course ➡️ bit.ly/2V4oEVJ ⚫️ bit.ly/2XMvqMs
PHP Programming Course ➡️ bit.ly/2XP71WH ⚫️ bit.ly/2vs3od6
Android Development Course ➡️ bit.ly/2UHih5H ⚫️ bit.ly/2IMhVci
C# Programming Course ➡️ bit.ly/2Vr7HEl ⚫️ bit.ly/2W6RXTU
JavaFx Programming Course ➡️ bit.ly/2XMvZWA ⚫️ bit.ly/2V2CoAi
NodeJs Programming Course ➡️ bit.ly/2GPg7gA ⚫️ bit.ly/2GQYTQ2
Jenkins Course For Developers and DevOps ➡️ bit.ly/2Wd4l4W ⚫️ bit.ly/2J1B1ug
Scala Programming Tutorial Course ➡️ bit.ly/2PysyA4 ⚫️ bit.ly/2PCaVj2
Bootstrap Responsive Web Design Tutorial ➡️ bit.ly/2DFQ2yC ⚫️ bit.ly/2VoJWwH
MongoDB Tutorial Course ➡️ bit.ly/2LaCJfP ⚫️ bit.ly/2WaI7Ap
QT C++ GUI Tutorial For Beginners ➡️ bit.ly/2vwqHSZ
★★★ Online Courses to learn ★★★
Get 2 FREE Months of Unlimited Classes from skillshare - skillshare.eqc...
Data Science - bit.ly/2lD9h5L | bit.ly/2lI8wIl
Machine Learning - bit.ly/2WGGQpb | bit.ly/2GghLXX
Artificial Intelligence - bit.ly/2lYqaYx | bit.ly/2NmaPya
MERN Stack E-Degree Program - bit.ly/2kx2NFe | bit.ly/2lWj4no
DevOps E-degree - bit.ly/2k1PwUQ | bit.ly/2k8Ypfy
Data Analytics with R - bit.ly/2lBKqz8 | bit.ly/2lAjos3
AWS Certification Training - bit.ly/2kmLtTu | bit.ly/2lAkQL1
Projects in Java - bit.ly/2kzn25d | bit.ly/2lBMffs
Machine Learning With TensorFlow - bit.ly/2m1z3AF | bit.ly/2lBMhnA
Angular 8 - Complete Essential Guide - bit.ly/2lYvYRP
Kotlin Android Development Masterclass - bit.ly/2GcblsI
Learn iOS Programming Building Advance Projects - bit.ly/2kyX7ue
★★★ Follow ★★★
My Website - www.codebind.com
DISCLAIMER: This video and description contains affiliate links, which means that if you click on one of the product links, I’ll receive a small commission. This help support the channel and allows us to continue to make videos like this. Thank you for the support!
Creating sql database connection in asp.net web application
How to make database connectivity in asp.net
Make connection to database in ASP.NET
c# - asp.net database connection
connect jqgrid to database
using WebSecurity.InitializeDatabaseConnection() to
CREATE DATABASE permission denied in database
How to connect asp.net to a database
Create a separated class for database connection
Tip: Don't place your conn.Close() inside the try block. If an exception is thrown before it reaches that line, the connection won't close. Best practice is to always place it in a "finally" block, and make your SqlConnection variable global.
Excellent tutorial as usual.
I thankyou very much and pray God bless all your endeavors
Great video and I'm beginner for ASP.NET Web Programming.
Good turtorial but .. for beginners. It is important to learn also good programming habits ex: sql injection - you need to use sql parameters, in sql tables we can use (and its much easier) autoincrement identity fields for unique ID's - the database will do it for you.
I don't know why but your tutorials are better than any American or German. You go through the matter of creating everything in one video where other people use pre-made forms.
hey i am watching your videos from tutorial 1 and to be honest they are very helpful.Thanks so much..
Great tutorial session. Thanks to all of you for your invaluable contribution to this online forum.
bro i love you... u jst solved my prblm in minutes.... @@@salute.
Thank you very much for this tutorial. It was a great help. Thank you for explaining things slowly and methodically. Also to solve the problem with the table name problem I did the following: [dbo].[Table] it worked for me.
hey bro ..you can type 'if' and hit 'tab' once or twice and it will get you that 'if' snippet much quicker. This also works for other things like for loops, while loops, etc :)
This works. Also use parameterized queries to avoid SQL injections.
SqlCommand checkuser = new SqlCommand("SELECT COUNT(*) FROM [UserData] WHERE ([UserName] = @UserName)", conn);
checkuser.Parameters.AddWithValue("@UserName", TextBoxUN.Text);
int temp = (int)checkuser.ExecuteScalar();
if (temp > 0)
{
Response.Write("User already exists!");
}
conn.Close();
Remember to make ID null and not a primary key inside Userdata, otherwise you will get an error since you would be leaving the primary key Null since we're not adding a value yet
thank you. i had the same error. Solved now!
Thank you so much!! such a good guy haha
thank uuuu
Good it's work, but the ID field in the table Userdata must be declared as PRIMARY KEY IDENTITY go to Column properties below of it scroll down and find Identity Specification, expand it and you will find Is Identity make it Yes. Now choose Identity Increment right below of it give the value you want to increment in it.
Fantastic tutorial. I have learned so much! Thank you!!
Thanks for your clear and detailed explanation!
ALTHOGH IT IS SO SLOW BUT IT IS SOOO HELPFUL. THANK YOU SO MUCH SIR
very very thankful to you to provide such a video...... thanks for your excellent effort.
I Want To know Is it mendetory to learn html for building webpages using asp.net ?
I Got the Coding and its working... I checked ..
Paste the below coding in your program
Write the code in page load.. If you want else function u can use...
otherwise u can leave it.
u can use if statement only.
if anyone have doubt can ask
Page_Load
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["UserDBConnectionString"].ConnectionString);
using (SqlCommand cmd = new SqlCommand("select * from tblUserdata where UserName = @uname", con))
{
con.Open();
cmd.Parameters.AddWithValue("@uname", TextBoxUN.Text);
SqlDataReader dr = cmd.ExecuteReader();
if (dr.HasRows)
{
Response.Write("userid already exists");
Response.Redirect("UserDBDetails.aspx");
}
else
{
Response.Write("userid doesn't exists");
//Create new user
}
}
}
This is an excellent series and much appreciated, although considering some of the ungrateful comments you get I wonder why you bother.
Is there any particular reason/benefit why the check for the unique username is performed in the form's Load section as opposed to the button.click? It just seems that to me that it would seem more logical to have it all in the button.click subroutine.
getting error on this line somebody plz help
line23: int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
my code is this--
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
namespace LoginPage
{
public partial class Registration : System.Web.UI.Page
{
int temp = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
string checkUserdata = " select count(*) from [UserData] where='" + TextBoxUN.Text + "'";
SqlCommand com = new SqlCommand(checkUserdata, conn);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
if (temp == 1) {
Response.Write("User already exist");
}
conn.Close();
}
}
protected void TextBox5_TextChanged(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void TextBox4_TextChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
string insertQuery = "insert into UserData(UserName,Email,Password,Country) values (@Uname,@email,@password,@country) ";
SqlCommand com = new SqlCommand(insertQuery, conn);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
conn.Close();
com.Parameters.AddWithValue("@Uname", TextBoxUN.Text);
com.Parameters.AddWithValue("@email", TextBoxEmail.Text);
com.Parameters.AddWithValue("@password", TextBoxPass.Text);
com.Parameters.AddWithValue("@country", DropDownCountry.SelectedItem.ToString());
com.ExecuteNonQuery();
Response.Redirect("Manager.aspx");
Response.Write("Registration completed");
}
catch (Exception ex)
{
Response.Write("Error" + ex.ToString());
}
}
}
}
in order to solve the problem about Convert.ToInt32(com.ExecuteScalar().ToString());
you need to change the upper line as;
string checkuser = "select count(*) from [UserData] where UserName = ' "TextBoxUN.Text"'";
simply put square brackets to each side of the tables name
Thank you so much !
thanks it worked
wonderful woow my problem is solve thankx Hamza
Thanks man
Hamza Karabağ i
you have really made it easy for me
thanks man
It Helped alot!!!jazakiAllaah
Its good...it would be more easier if you had attached the code in text form so that we can only copy paste :)
With the code you have demonstrated, adding a new user with a username that already exists in the database does not show the error message you posted, it adds the users to the database regardless of already being in the database.
True,
I even added debug code to that if (IsPostBack) statement. So my guess is that none of it gets called.
Exactly, this basically means that once the page is loaded then the code written will be executed, but my guess is it's not executed because the user is directed to another page.
박송미
This is correct. I took out the redirection code that was fired when you press the regsiter button and now it gets called. It's a bit pointless having a button that just submits user data and refreshes the page but I suppose it'll have to do for now.
By the way it's probably a better idea to check that 'temp' is not 0, rather than is 1.
So it looks like
if (temp !=0){
Response.Write("user already exists);
}
I've managed to get mine working. I've put the code onto pastebin, feel free to look at it. It's in VB.NET but it shouldn't be too hard to port it over to C#
pastebin.com/YSDH9Q5w
It's pretty messy at the moment but I'll get round to refactoring eventually
Thanks! I'll definitely check it out !
I like how he says "Okey?" sometimes :) I'm here saying YUS! to my screen everytime he says that ;)
nice tutorial very helpfull
hello
Good serial to learn ASP.net v good explaniation
But backround sounds are distarbing pls minimise tha backround sounds in further vedios
hi, there is a bug.. whenever u click on button and having same Username "temp will increment by 1" so add carl several time and u will see that one time it goes through "user already exist" and all will be inserted to database so on button_click we should have restriction when temp==1 to avoid inserting the values. If am wrong plz inform me .
99% successful in one attempt. only check user is not working in "ASP.NET Tutorial 4". It accepts same usernames without any error. and you have not performed cross check in the video where a same username is entered it should give a error message. Thank you for your great tutorials. please reply
+Manoj Yadwad Same problem
try this:
public partial class Registration : System.Web.UI.Page
{
Int32 temp = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
string checkuser = "select count(*) from [userdata] where Username='" + username.Text + "'";
SqlCommand com = new SqlCommand(checkuser, conn);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
if (temp > 0)
{
MessageBox.Show("already exist");
Response.Redirect("Registration.aspx");
}
conn.Close();
}
}
protected void Button3_Click(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
string insertquery = "insert into [userdata] (Username,Email,Password,Country) values(@uname,@email,@password,@country) ";
SqlCommand com = new SqlCommand(insertquery, conn);
com.Parameters.AddWithValue("@uname", username.Text);
com.Parameters.AddWithValue("@email", email.Text);
com.Parameters.AddWithValue("@password", password.Text);
com.Parameters.AddWithValue("@country", droplist.SelectedItem.ToString());
com.ExecuteNonQuery();
MessageBox.Show("Successfully submitted");
Response.Redirect("Manager.aspx");
conn.Close();
}
catch (Exception E)
{
Response.Write("Error" + E.ToString());
}
}
}
thts not work
Thanks a lot
i got perfect out put
Thank You Very Much Sir.
for null object reference
go to web config and add:-
for appropriate connectionString="Data Source=....."
go to your Registration database right click
select proprieties
copy connection string from their.
Hope this helps.
great worked so far (y)
hello, your tutorials are awesome. I receive this error "Object refference not set to an instance of an object" on the line where I create the new sqlconnection. can you help me, please?!
Video is good but i wish you would explain what all the lines of code mean.
Hi,
Why you are writing code in Pageload() and where you are using it or where it is utilized?
thank u sir
please provide us syllabus of asp.net
Your video was good but you didnt provide the solution for username exists..
If you are pasting such a good video you should provide relevant solutions for the subscribers..@ProgrammingKnowledge
Same reply functionality is not working sir
Error solved
Just remove the double qoutes from checkUser like
before
SqlCommand com = new SqlCommand("checkUser", conn);
then after
SqlCommand com = new SqlCommand(checkUser, conn);
welcome
Subscribe my channel please
@@code_aalim In the video there are no double quotes, and duplicates still happen, please help @ProgrammingKnowledge
good channel
"when i click submit, it just reloads the same registration form with passwords empty, and doesn't save data to the Database. Doesn't redirect to manager.aspx, and no success message either. And no error either". I have the same problem, any suggestion?
int temp = Convert.ToInt32(con.ExecuteScalar().ToString()); it gives error at these line at the semicolen stuff
Yes same error
Yeah even I'm getting this same error
@@sandhyashirsath have you got any solution then plz tell me
Same error
God bless you!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
great videos, subscribed :)
Best tutorial
You didnt test to see what happens when you enter a user name that is already there. The way you have it, it still adds the user even if the username is already there.
Ok, so I used a static boolean variable in a new class file I added. If there is a dup user then i set it to true and check the value in button_click. If its true i just use the "return" word to bypass submit button click code.
Error solved
Just remove the double qoutes from checkUser like
before
SqlCommand com = new SqlCommand("checkUser", conn);
then after
SqlCommand com = new SqlCommand(checkUser, conn);
welcome
Subscribe my channel, please
Slightly modify the code to show "User already Exists"
public partial class LoginPage : System.Web.UI.Page
{
int temp=0;
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
string checkuser = "select count(*) from registration where username='" + TBusername.Text + "'";
SqlCommand com = new SqlCommand(checkuser, conn);
temp = Convert.ToInt32(com.ExecuteScalar().ToString());
if (temp==1)
{
Response.Write("User already exists");
}
conn.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
if (temp == 0)
{
try
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
string insertquery = "insert into registration (username,emailid,password,country) values (@uname,@email,@password,@country)";
SqlCommand com = new SqlCommand(insertquery, conn);
com.Parameters.AddWithValue("@uname", TBusername.Text);
com.Parameters.AddWithValue("@email", TBemail.Text);
com.Parameters.AddWithValue("@password", TBpass.Text);
com.Parameters.AddWithValue("@country", DDcountry.SelectedItem.ToString());
com.ExecuteNonQuery();
Response.Redirect("Managers.aspx");
Response.Write("Registration Successful");
conn.Close();
}
catch (Exception ex)
{
Response.Write("error :" + ex.ToString());
}
}
}
}
Thanks. You might want to change "if (temp == 1)" with "if (temp != 0)". This will also show the message.
***** Can you provide me how you fix this issue
Mohammed Zahid
Good thing I looked at your comment. You pointed me to the right direction! Thanks!
Mohammed Zahid it didn't helped
am getting this error NullReferenceException: Object reference not set to an instance of an object
Thank you very much..
.
Thank a lot sir appreciated
ser ye sab vedios hindi me banaye taki jinko english nhi vi bhi ye sab sikh sake pls.......
An expression of non-boolean type specified in a context where a condition is expected, near 'raja ba'.
sir igot a Exception on line 19
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
pls help me
Did you solve your error???
Use "select *" instead of "select count(*)"
Replace temp statement with:
SqlDataReader reader = com.ExecuteReader();
if (reader.HasRows)
{
//User already exists
}
else
{
//Doesn't exist
}
dude you are the best
thank you so much ..........
After executing it, I can enter values in Username,... fields but after submitting it is showing an error: "An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code". Can you please suggest me to correct it. Thank you.
Thanks a ton!
int temp = Convert.ToInt32(con.ExecuteScalar().ToString());
I had that problem. I just made everything from the very begining and it works now. I think that a name of table cannot be "Table". Try that
Your tutorials are very useful! As a beginner, I find these steps very easy to follow. :)
I just have a question. I tried using the same username but it didn't display the message "User already exists". Could you please check this code that I'm using? Thanks in advance!
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class Registration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if(IsPostBack)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
string checkuser = "select count(*) from UserData where UserName='" + TextBoxUsername.Text + "'";
SqlCommand com = new SqlCommand(checkuser, conn);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
if (temp == 1)
{
Response.Write("User already exists");
}
conn.Close();
}
}
protected void Button1_Click1(object sender, EventArgs e)
{
try
{
Guid newGUID = Guid.NewGuid();
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
string insertQuery = "insert into UserData (ID,UserName,Email,Password,Country) values (@ID ,@Uname ,@email ,@password ,@country)";
SqlCommand com = new SqlCommand(insertQuery, conn);
com.Parameters.AddWithValue("@ID", newGUID.ToString());
com.Parameters.AddWithValue("@Uname", TextBoxUsername.Text);
com.Parameters.AddWithValue("@email", TextBoxEmail.Text);
com.Parameters.AddWithValue("@password", TextBoxPw.Text);
com.Parameters.AddWithValue("@country", DropDownListCountry.SelectedItem.ToString());
com.ExecuteNonQuery();
Response.Redirect("Manager.aspx");
Response.Write("Registration is successful");
conn.Close();
}
catch(Exception ex)
{
Response.Write("Error:"+ex.ToString());
}
}
}
how to fix in this line:
int temp = Convert.ToInt32(con.ExecuteScalar().ToString());
Description: Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidOperationException: ExecuteScalar: Connection property has not been initialized.
- via YouPak(.com)
+nargis ehsan add [] to your table name e.g. [Table]
+shubham jain i had the same error but for some reason it did't fix it i type the table name in the square bracket
hey nargis i m having d same error hw shld i crrct it.?????/
getting error on this line somebody plz help
line23: int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
my code is this--
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
namespace LoginPage
{
public partial class Registration : System.Web.UI.Page
{
int temp = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
string checkUserdata = " select count(*) from [UserData] where='" + TextBoxUN.Text + "'";
SqlCommand com = new SqlCommand(checkUserdata, conn);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
if (temp == 1) {
Response.Write("User already exist");
}
conn.Close();
}
}
protected void TextBox5_TextChanged(object sender, EventArgs e)
{
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
}
protected void TextBox4_TextChanged(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
string insertQuery = "insert into UserData(UserName,Email,Password,Country) values (@Uname,@email,@password,@country) ";
SqlCommand com = new SqlCommand(insertQuery, conn);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
conn.Close();
com.Parameters.AddWithValue("@Uname", TextBoxUN.Text);
com.Parameters.AddWithValue("@email", TextBoxEmail.Text);
com.Parameters.AddWithValue("@password", TextBoxPass.Text);
com.Parameters.AddWithValue("@country", DropDownCountry.SelectedItem.ToString());
com.ExecuteNonQuery();
Response.Redirect("Manager.aspx");
Response.Write("Registration completed");
}
catch (Exception ex)
{
Response.Write("Error" + ex.ToString());
}
}
}
}
hey can u just tell what error are u seeing on that line
I have tried this piece of code it is working there's no error but there is one bug that it is also accepting duplicate entries of username.... kindly revert with the solution...
I have the newest version of ASP.net and I don't have the "page_load" thing ..
but I have .. TextBox4_TextChanged & Button1_Click
where can I put the code you wrote instead of the "page_load"?!!
how did you solve it? I have the exact same problem
what does this error means ?
"Invalid postback or callback argument. Event validation is enabled using in configuration or in a page. For security purposes, this feature verifies that arguments to postback or callback events originate from the server control that originally rendered them. If the data is valid and expected, use the ClientScriptManager.RegisterForEventValidation method in order to register the postback or callback data for validation."
you missed to clarify the ID how to replace in database
Sir you're great but change this line 20 to this
string checkuser= "select count(*)from [UserData] where UserName= '"+TextBoxUN.Text +"'";
other code is okay
if anybody out there is getting:
No mapping exists from object type System.Web.UI.WebControls.ListItem
add the toString() to the end of your drop down list item:
com.Parameters.AddWithValue("@country",
DropDownListCountry.SelectedItem.ToString());
hi bro i am using vs 2015 when i double click on submit button it is going to the .aspx file but in video it is going to the .aspx.cs file plz help me how can i do that.how can i write sql connection commands plz help me
it works!
I did everything as shown in the video and im getting 2 errors one in sqldatasource box tat it doesn't contain select query and another one is on Conn.Open();...pls help me to fix thus problem
its not showing username already exist...instead its going on taking the same username n saving it in database
is it necessary to create a Manager.aspx for the connection string?
he said it was for demonstration purposes only like to be able to see the newly added user in the database
and One more thing , you have so many using system and I don't have any
When I click twice at the button "Submit" it redirects me to a created at the .aspx file instead of redirecting me to the .cs file. When I create, by myself, the .cs file I get some errors calling the TextBoxs.
How can I solve it?
I can work at the (at .aspx file) but how do I call the c# libraries like:
"using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;"
Thank you.
How do you make numbers in Id column to increment every time you register someone new?
+Victor Dyusha use identity ........ such as (id int identity primary key)
You just... you just... YES we just, but can you explain why are you writing the code ?
For Example, why do you need " if (isPostBack) " and so on !?
It is for checking if the page goes from a fresh load or from a post action, it returns a boolean
sir i really need help because this all code is written in c# and I need visual basic
Please help me with this error
"Type 'System.Web.UI.WebControls.SqlDataSource' does not have a public property named 'SelectQuery ".
What can i do?
same issue! ... still have it?
Same Here. . .
IT SHOULD BE LIKE THIS
after doing the change the problem is not solved. ;( ;( please help
@@thanemane I solve this problem using what Carl Patrick Guerrero use in the SqlDataSource
then add in your
he i am bsc it student i want to ask you some questions about my project can you help me?
ProgrammingKnowledge
Great tutorial Sir. But whenever I try to run the program. It gives me this error:
"A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)"
It' having some problem with Opening the connection. Any solutions to this problem?
User already exist is not working, even entering same user name multiple times its saving in to database table, any corrections here ?
Just so you know change the if statement from if(temp == 1) to if(temp >= 1), just in case somebody is testing
Not working
very good code but when i click on the submit jast reload and the data not in the database how can i fix it ? please help
Error 2 'ASP.default_aspx' does not contain a definition for 'TextBox1_TextChange' and no extension method 'TextBox1_TextChange' accepting a first argument of type 'ASP.default_aspx' could be found (are you missing a using directive or an assembly reference?) C:\Users\user\Documents\Visual Studio 2010\WebSites\WebSite1\Default.aspx 104
i got this error how to fix it?
Can you create canteen project please
int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
this line is giving me error
An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code.
please help!!
But I needs update and delete data in data connection string or database table
I insert an existing user name but the registration is also successful. The statement "User already exists" doesn't appear. Why?
Can you show the whole code at the end? there is no way to verify if the correct code is entered.
I finally got it functional. Here my code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
public partial class Registration : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
string checkuser = "select count(*) from [UserData] where Username='"+ TextBoxUN.Text + "'";
SqlCommand com = new SqlCommand(checkuser, conn);
int temp = Convert.ToInt32(com.ExecuteScalar().ToString ());
if (temp == 1)
{
Response .Write ("User already Exists");
}
conn .Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
try
{
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["RegistrationConnectionString"].ConnectionString);
conn.Open();
string insertQuery = "INSERT INTO [UserData] ([UserName],[Email],[Password],[Country]) VALUES (@Uname ,@email ,@password ,@country)";
SqlCommand com = new SqlCommand(insertQuery, conn);
com.Parameters.AddWithValue("@Uname", TextBoxUN.Text);
com.Parameters.AddWithValue("@email", TextBoxEmail.Text);
com.Parameters.AddWithValue("@password", TextBoxPass.Text);
com.Parameters.AddWithValue("@country", DropDownListCountry.SelectedItem .ToString ());
com.ExecuteNonQuery();
Response.Write("Account has been successfully created");
Response.Redirect("Manager.aspx");
conn.Close();
}
catch (Exception ex)
{
Response.Write("Error:" +ex.ToString());
}
}
}
thanks this works!
I have exception here int temp = Convert.ToInt32(com.ExecuteScalar().ToString()); when I press submit button please send me full code.
I had already same problem.but it solved! you should change your Table name that you saved in database .change the name Table to Table1 or something else
Thanku Sir
I know it is late ...But i have a doubt and i really need to run the code...I have done all the forms and databse there is no issue in it bt When I run it takes me to Registration Page .cs code showing mess that object not set to an instance of an object..I f any body know Plzz help me with it ...
my error generate inccorrect syntax near 'UserData'
this is my select string = select count(*) from Table where UserData = '" + txtUN.Text + "'";
whats the error?
error:
Line 19: SqlCommand com = new SqlCommand(checkuser, con);
Line 20:
Line 21: int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
Line 22: if (temp == 1)
Line 23: {
I have done all the things you said but when i click on the submit button nothing happens just the page reloads!
What am i supposed to do???!!!
please help!!!
thanq .
The username validation is not working. No one is providing complete answers.
my error generate inccorrect syntax near 'UserData'
this is my select string = select count(*) from Table where UserData = '" + txtUN.Text + "'";
whats the error?
+jenan savanath You need to encapsulate your Table with []. Example: select count(*) from [Table]
+eliteowner121 oh yeah i forgot about that...thanks. I totally forgot about 'Table' being a reserved keyword.
conn.parameters.addwithvalue is code line m parameter par error show kar raha hai plz tell me how can i remove it
errorSystem.NullReferenceException: Object reference not set to an instance of an object. at registration.WebForm1.Button1_Click(Object sender, EventArgs e) in c:
egistration
egistration\WebForm1.aspx.cs:line 38
The page is still adding the same user name registration i just typed the same code as you did...
+Noshair Farooq Yes same here.I guess this is not the code
well do share if you get it right
+Noshair Farooq Yeah, I was thinking the same, he didn't even try to write same name in this demo, if he did, I'm sure he would get same outcome as we do.. I hope someone can help us with this, as it's quite important to not allow the users to choose same username, but to get some sort of validation, where it wouldn't allow same UserName to be used twice. I'll probably just google it tbh :D
+Noshair Farooq oh i thought I was the only one experiencing this and I was also hoping that he would try to input the same username. :(
why did you put the userCheck in page_load event?
I encounter an error
Must declare the scalar variable "@FName". at System.Data.SqlClient.SqlConnection.
S Showing error the name 'TextUn' does not exist in the current context regis
I have also Noticed that , ID does Not Auto Increment during Registration .
Set that too !!!
Although i followed same codes, still another user could be created with the same user name. Why is it?