Results 1 to 5 of 5

Thread: [RESOLVED] sql results to a messagebox

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    31

    Resolved [RESOLVED] sql results to a messagebox

    Is there a way to send the results of a sql statement to a messagebox?

  2. #2
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    675

    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..."

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    31

    Re: sql results to a messagebox

    Just one value, no tables.

  4. #4
    Fanatic Member
    Join Date
    Nov 2006
    Posts
    675

    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..."

  5. #5

    Thread Starter
    Junior Member
    Join Date
    Jan 2007
    Posts
    31

    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
  •  



Click Here to Expand Forum to Full Width