|
-
Mar 19th, 2007, 04:21 PM
#1
Thread Starter
Junior Member
[RESOLVED] sql results to a messagebox
Is there a way to send the results of a sql statement to a messagebox?
-
Mar 19th, 2007, 04:30 PM
#2
Fanatic Member
Re: sql results to a messagebox
There are many ways. But what do you mean, exactly?
Is there just one result, like a sum or max? Or does it return a table?
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Mar 19th, 2007, 04:32 PM
#3
Thread Starter
Junior Member
Re: sql results to a messagebox
Just one value, no tables.
-
Mar 19th, 2007, 04:35 PM
#4
Fanatic Member
Re: sql results to a messagebox
Dim sqlCmd as new SqlClient.SqlCommand
Dim Result as Integer (or string, or decimal, whatever the result will be)
SqlCmd.CommandText = "Your query here"
sqlCmd.Connection = YourSQLConnection
YourSQLConnection.Open()
Result = sqlCmd.ExecuteScalar
YourSQLConnection.Close()
TextBox1.Text = Result.ToString
This is pretty much just psuedocode, and I typed it straight into the editor. But the ExecuteScalar part is what I think you are after. After you have it stored in Result (or whatever you name your variable) it is very easy to put it in a textbox, or do whatever else you want to do with it.
Oh, and the open, executescalar, and close lines need to be put in a try/catch block so your program doesn't crash if there is an error.
VB.Net 2008
.Net Framework 2.0
"Must you breathe? 'Cause I need heaven..."
-
Mar 19th, 2007, 04:41 PM
#5
Thread Starter
Junior Member
Re: sql results to a messagebox
Exaclty what I needed! Thank You!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|