How to use VB with an SQL server
-
Monday, September 29, 2008 2:50 PMHello. I am new to using SQL and some what new to using VB but i need help with an application i am working on. I have an SQL database that will have user names and passwords that i want my VB program to retrieve. How can i pull out the data i need in the database and compare it to the data that the user just input to the program?
Thanks for your help.
Pierre
All Replies
-
Tuesday, September 30, 2008 12:14 AM
you can try How to insert and retrieve data from sql server from vb net ApplicationThis might help you
Prateek Regmi Blog for Programmers- Marked As Answer by Martin Xie - MSFT Thursday, October 02, 2008 5:57 AM
-
Tuesday, September 30, 2008 8:48 AM
Hello Turc,
Please check out the how do I videos.
How Do I in Visual Basic
Waleed El-Badry Teaching Assistant Faculty of Engineering Misr University for Science & Technology- Proposed As Answer by Waleed El-Badry Tuesday, September 30, 2008 8:52 AM
- Marked As Answer by Martin Xie - MSFT Thursday, October 02, 2008 5:57 AM
-
Thursday, October 02, 2008 6:41 AM
Turc said:
I have an SQL database that will have user names and passwords that i want my VB program to retrieve. How can i pull out the data i need in the database and compare it to the data that the user just input to the program?
Thank you All for your friendly help.
Hi Pierre,
Welcome to MSDN forums!Please check and try the following code samples.
Code sample 1:Imports System.Data.SqlClient Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim con As New SqlConnection("Data Source=.;Integrated Security=True;AttachDbFilename=D:\MyDB.mdf") Dim cmd As SqlCommand = New SqlCommand("SELECT UserName,UserPassword FROM UserTable", con) con.Open() Dim sdr As SqlDataReader = cmd.ExecuteReader() While sdr.Read = True If sdr.Item("UserName") = TextBox1.Text Then MessageBox.Show("The user exists in database!") End If End While sdr.Close() con.Close() End Sub End Class
Code sample 2:
Imports System.Data.SqlClient Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click Dim con As New SqlConnection("Data Source=.;Integrated Security=True;AttachDbFilename=D:\MyDB.mdf") Dim cmd As SqlCommand = New SqlCommand("SELECT UserName,UserPassword FROM UserTable WHERE UserName = '" & TextBox1.Text & "'", con) con.Open() Dim sdr As SqlDataReader = cmd.ExecuteReader() If sdr.Read() = True Then MessageBox.Show("The user exists in database!") End If sdr.Close() con.Close() End Sub End Class
Walkthrough: How to make a Login Verification routine (Login Form)?
http://social.msdn.microsoft.com/forums/en/vbgeneral/thread/4eb4dc84-a62f-4a46-95b0-3b981fb83f23/
Best regards,
Martin Xie- Edited by Martin Xie - MSFT Thursday, October 02, 2008 6:43 AM Edit
- Proposed As Answer by Corey Furman Thursday, October 02, 2008 11:32 AM
- Marked As Answer by Martin Xie - MSFT Friday, October 03, 2008 9:43 AM

