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?



    Thursday, March 19, 2009 7:40 AM


  • 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)
    			Using adapter As New SqlDataAdapter(cmd)
    				Dim ds As New DataSet
                          ' 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