locked
How can i check if the sqlcommand contain values? RRS feed

  • Question

  • User-410551326 posted

    The code: 

    SqlCom = New SqlCommand("SELECT * from ItonUsers Where UserName='" + UserName + "'", MyConnection)

    So how can i check if the SqlCom contain result?

    [vb.net]

    Thank!

    Thursday, March 19, 2009 7:40 AM

Answers

  • User-1995538749 posted

    You can do something like this if you plan on retrieving a DataSet: 

    Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("NorthwindConnectionString").ConnectionString)
    	Using cmd As New SqlCommand("SELECT * FROM [Shippers]", conn)
    		Try
    			conn.Open()
    			Using adapter As New SqlDataAdapter(cmd)
    				Dim ds As New DataSet
    				adapter.Fill(ds)
    
                          ' Here's where you get your count
                          Dim count = ds.Tables(0).Rows.Count
                      End Using
    		Catch ex As Exception
    			' Do something here
    		End Try
    	End Using
    End Using
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, March 19, 2009 8:13 AM