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?

Re: Looking up a record in a table by Cor

Cor
Sat Jun 10 00:56:23 CDT 2006

Bob

I think that the easiest is to use an command.ExecuteScalar with a SQL
transact script string that contains a Where clause

ExecuteScalar (idb = for SQLSever SQLClient and for OledB OleDB)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatasqlclientsqlcommandclassexecutescalartopic.asp

Where clause
http://msdn2.microsoft.com/en-us/library/ms188047(SQL.90).aspx

I hope this helps,

Cor


"BobRoyAce" <broy@omegasoftwareinc.com> schreef in bericht
news:1149917821.552008.50370@f6g2000cwb.googlegroups.com...
>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?
>



Re: Looking up a record in a table by BobRoyAce

BobRoyAce
Sat Jun 10 01:07:22 CDT 2006

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?


Re: Looking up a record in a table by Cor

Cor
Sat Jun 10 02:18:57 CDT 2006

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






"BobRoyAce" <broy@omegasoftwareinc.com> schreef in bericht
news:1149919642.675325.180470@g10g2000cwb.googlegroups.com...
> 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?
>