SQL Check if a record exists
-
Look...i'm really not good with sql since i don't do it that often...can someone please give me a really dumbed down answer so i understand. I am sorta just getting into using sql. How do i check if a record exists, i need to know everything, i have a table called users. When a user puts a username in a textbox, how do i check if a record exists with there user name.
Please check out my articles: The ANZAC's articles
-
Look...i'm really not good with sql since i don't do it that often...can someone please give me a really dumbed down answer so i understand. I am sorta just getting into using sql. How do i check if a record exists, i need to know everything, i have a table called users. When a user puts a username in a textbox, how do i check if a record exists with there user name.
Please check out my articles: The ANZAC's articles
just put it in the where clause and check if you get a record back: sql: select username from users where username='me' then you just check you'r datareader/adapter if there is a record in it if so the user exist of not the user doesn't exist hope this helps
If my help was helpfull let me know, if not let me know why. The only way we learn is by making mistaks.
-
Look...i'm really not good with sql since i don't do it that often...can someone please give me a really dumbed down answer so i understand. I am sorta just getting into using sql. How do i check if a record exists, i need to know everything, i have a table called users. When a user puts a username in a textbox, how do i check if a record exists with there user name.
Please check out my articles: The ANZAC's articles
HI The ANZAC Follow me. Lets say i have a textbox in my form and i want to see if there is a user name that Exist in my table "Users", and am using VB.NET. the First thing is to set up the adapter. you must tell the adapter that you going to Accept inputs from users. e.g
SELECT USERS FROM MYTABLE WHERE (USERNAME = @USERNAME)
When you are done with that create a dataset and Fill your dataset with Data like this.
myadapter.Fill(mydataset)
After that , you need to call this from your form. in your form put in a Button , call it "btnSearch", and in the button click event write the Following code.
try
myadapter.SelectCommand.Parameters("@Username").Value = txtUsername.Text
mydataset.Clear()
myadapter.Fill( mydataset, "MYTable")
If mydataset.Tables("MYTable").Rows.Count = 0 Then
MessageBox.Show("The USERNAME does not Exist in the Database you can Continue Add it", "Info", MessageBoxButtons.OK)
Else
MessageBox.Show("The Property Exist in the Database, you cannot Add this liskey", "Error", MessageBoxButtons.OK)
End If
Catch ex As SqlClient.SqlException
MessageBox.Show(ex.Message)
End TryHope this Helps, if doesnt TEll me
Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sudden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za
-
HI The ANZAC Follow me. Lets say i have a textbox in my form and i want to see if there is a user name that Exist in my table "Users", and am using VB.NET. the First thing is to set up the adapter. you must tell the adapter that you going to Accept inputs from users. e.g
SELECT USERS FROM MYTABLE WHERE (USERNAME = @USERNAME)
When you are done with that create a dataset and Fill your dataset with Data like this.
myadapter.Fill(mydataset)
After that , you need to call this from your form. in your form put in a Button , call it "btnSearch", and in the button click event write the Following code.
try
myadapter.SelectCommand.Parameters("@Username").Value = txtUsername.Text
mydataset.Clear()
myadapter.Fill( mydataset, "MYTable")
If mydataset.Tables("MYTable").Rows.Count = 0 Then
MessageBox.Show("The USERNAME does not Exist in the Database you can Continue Add it", "Info", MessageBoxButtons.OK)
Else
MessageBox.Show("The Property Exist in the Database, you cannot Add this liskey", "Error", MessageBoxButtons.OK)
End If
Catch ex As SqlClient.SqlException
MessageBox.Show(ex.Message)
End TryHope this Helps, if doesnt TEll me
Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sudden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za
This is helping, but where do i put that select statement, i am really new to this.
Please check out my articles: The ANZAC's articles
-
just put it in the where clause and check if you get a record back: sql: select username from users where username='me' then you just check you'r datareader/adapter if there is a record in it if so the user exist of not the user doesn't exist hope this helps
If my help was helpfull let me know, if not let me know why. The only way we learn is by making mistaks.
i appreciate the help, but i am not at all database experienced and to me this is extremely vague, i'm seriously like a lost sheep when it comes to this, you need to be really detailed for me. thanks though.
Please check out my articles: The ANZAC's articles
-
This is helping, but where do i put that select statement, i am really new to this.
Please check out my articles: The ANZAC's articles
i suggest you use the Wizard for now, as you are new. drag an Adapter from your ToolBox, The wizard will popin and Click next, if you have no Connection create a new one, if you are using Access as a Backend choose JET4 provider and select where the database is and test the connection. after that right click on the adapter and choose Configure the adapter --> and you will see that database had been selected and click next-->:Choose the First Opttion "Use SQl statement", ---> Next this Part its where you put your SQL statement, after that you will click next, all neccessary command statement will be generated for Update, select and Delete and Click Finish hope it Helps
Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sudden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za
-
i suggest you use the Wizard for now, as you are new. drag an Adapter from your ToolBox, The wizard will popin and Click next, if you have no Connection create a new one, if you are using Access as a Backend choose JET4 provider and select where the database is and test the connection. after that right click on the adapter and choose Configure the adapter --> and you will see that database had been selected and click next-->:Choose the First Opttion "Use SQl statement", ---> Next this Part its where you put your SQL statement, after that you will click next, all neccessary command statement will be generated for Update, select and Delete and Click Finish hope it Helps
Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sudden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za
This has helped. I managed to do it slightly different..in that it counts the amount of users which have the same name as the above. select count(*)
Please check out my articles: The ANZAC's articles
-
This has helped. I managed to do it slightly different..in that it counts the amount of users which have the same name as the above. select count(*)
Please check out my articles: The ANZAC's articles
AM Glad i helped you
Vuyiswa Maseko, Sorrow is Better than Laughter, it may Sudden your Face, but It sharpens your Understanding VB.NET/SQL7/2000/2005 http://vuyiswamb.007ihost.com http://Ecadre.007ihost.com vuyiswam@tshwane.gov.za