Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Returning column data...

Status
Not open for further replies.

skinrock

Programmer
Nov 20, 2004
23
US
Okay, I'm using VB.NET and SQL. Now, the accessing and updating of the database works fine. Now I'm trying to retrieve the data. So far I have:
Code:
sql_command.CommandText = "SELECT uid FROM userlist WHERE uname = ' " & txtUName.Text & " ' AND pword = ' " & txtPWord.Text & " '"
sql_command.ExecuteNonQuery()
What would I need to do to save the return value? I tried saying:
Code:
Dim result As Integer (and also As String)
result = sql_command.ExecuteNonQuery()
but all I ever get is -1, even when I say:
Code:
sql_command.CommandText = "SELECT uid FROM userlist"
So how do I save the value from a SELECT statement? Thanks!
 
Also, is there a different route you guys would use? Like using a dataset or something? I'm still fairly new to doing databases and VB.net, and the only thing I have available is this MSDE database, so I wasn't sure what other way I could access it other than through SQL queries.
 
the value you get in result is wether or not the sql-statement got executed or not. -1 means that it executed just fine. if you want to get that data you will have to put it in a datatable.

Code:
dim dt as new datatable
dim ad as new sqldataadapter
dim sql_command as new sqlcommand

'Connect sql_command too connection
sql_command.CommandText = "SELECT uid FROM userlist WHERE uname = ' " & txtUName.Text & " ' AND pword = ' " & txtPWord.Text & " '"
ad.selectcommand = sql_command
ad.fill(dt)
firstresult = dt.rows(0).item("uid")


Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top