Looking up a record in a table

  • Thread starter Thread starter BobRoyAce
  • Start date Start date
B

BobRoyAce

I am new to VB.NET and am currently using Visual Studio 2005. Let's say
that I have a Users table that has User information, including
LoginName and Password. I have a login form where the user types in a
login name and a password. Now, I want to go out to my SQL Server 2005
DB and query the Users table to see if a record exists for the entered
values. What's the best way to do something like this?
 
Thanks Cor. I'm afraid I was not totally clear. I don't just want to
know that the record exists. I also want to be able to pull values from
the record (e.g. UserFirstName, UserLastName, etc.). Should I use a
SqlDataReader? If so, could you show sample code on how I would do
something like that including how I would reference the two fields
mentioned above?
 
Bob,

I will only use the datareader if it is in batch processing.

For the rest the SQLdataadapter and datatable will do it fine, I assume
that you know how that is working.

\\\
Dim conn As New SqlClient.SqlConnection("Server = " & "Server" & _
"; Database = Whatever; " & _
"Integrated Security = sspi;")
'Replace in Server your servername or Ip address
Dim dt As New DataTable
Dim cmd As New SQLCommand("SELECT * FROM MyTable WHERE MyDate BETWEEN
@BeginDate And @EndDate", Conn)
cmd.Parameters.Add("@BeginDate", cdate(txtBeginDate.text))
cmd.Parameters.Add("@EndDate", cdate(txtEndDate.text))

DataGridView1.Datasource = dt
///

I hope this helps,

Cor
 
Back
Top