Checking for an SQL result in VB.NET

后端 未结 3 584
后悔当初
后悔当初 2021-01-26 03:14

I need to check if my SQL statement returned any results from the Access db I\'m using to store my data.

I have this code atm:

        cn = New OleDbConn         


        
3条回答
  •  花落未央
    2021-01-26 04:02

    Simple. Use the OleDbDataReader.HasRows Property after your call to ExecuteReader.

        cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=D:\Computing Project\database.mdb;")
        cn.Open()
        cmd = New OleDbCommand("SELECT * FROM(" & roomvar.ToLower() & ") WHERE (((" & roomvar.ToLower() & ".date)=" & Chr(34) & dtpDate.Value.Date & Chr(34) & "))", cn)
        dr = cmd.ExecuteReader
    
        hasRows = dr.HasRows
    
        dr.Close()
    

提交回复
热议问题