Quantcast
Channel: VBForums - Visual Basic .NET
Viewing all articles
Browse latest Browse all 27511

How to override NULL value returned by a SQL command?

$
0
0
I have a "small" problem. Namely, I want to delete data associated with p_ID value from a table. Before of that, I'm trying to check is there data which should be deleted or not.

vb Code:
  1. Dim amnt As integer
  2.         Using cn As New OleDb.OleDbConnection _
  3.   (db_path)
  4.             cn.Open()
  5.             Dim cmd As New OleDb.OleDbCommand("Select * FROM cards WHERE ID = """ & p_ID & """", cn)
  6.             amnt = cmd.ExecuteScalar()
  7.         End Using
  8.         If amnt = 0 Then
  9.             Exit Sub
  10.         Else
  11.  
  12.             Dim myConn As sqlConn = New sqlConn()
  13.             myConn.KonektujBazu("Delete From cards WHERE ID = """ & p_ID & """")
  14.             myConn.OLEComm.Connection = myConn.OLEConn
  15.             myConn.OLEComm.ExecuteNonQuery()
  16.             myConn.OLEConn.Close()
  17.  
  18.         end if
  19.     End Sub

I'm getting an error: "no value given for one or more required parameters". IF I understood that correctly, that's because my SQL returns no value. How's the best way to solve this kind of troubles?

Thanks in advance

Viewing all articles
Browse latest Browse all 27511

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>