Using RecordsAffected as a parameter

Please support our VB.NET advertiser: Intel Parallel Studio Home
Thread Solved

Join Date: Jan 2008
Posts: 97
Reputation: Estella is an unknown quantity at this point 
Solved Threads: 6
Estella's Avatar
Estella Estella is offline Offline
Junior Poster in Training

Using RecordsAffected as a parameter

 
0
  #1
Jun 10th, 2008
  1. SearchString = "SELECT * FROM Breakdown WHERE BFrom = " & txtFrom.Text ' & " AND BTo = " & txtTo.Text
  2. Dim Con As New OleDbConnection(BCalc_ConnectionString)
  3. Dim Search As New OleDbCommand(SelectSearchString, Con)

I want to stop users from being able to save a duplicate record in my Access database. I thought of using RecordsAffected, but I can't figure out how to get it to work.

That's how I've started. I want to be able to use the result of the RecordsAffected as a parameter in an IF statement so that
  1. IF Search.records affected = 0 THEN Insert records
  2. ELSE Display msgbox telling user that duplicate records aren't allowed.

Please Help...
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: Using RecordsAffected as a parameter

 
1
  #2
Jun 10th, 2008
see this code :
  1. Dim cn As OleDbConnection
  2. Dim cmd As OleDbCommand
  3. Dim dr As OleDbDataReader
  4. cn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\MyDB.mdb;")
  5. cn.Open()
  6. cmd = New OleDbCommand("SELECT * FROM Breakdown WHERE BFrom = '" & txtFrom.Text & "'", cn)
  7. dr = cmd.ExecuteReader
  8. If dr.Read()
  9. MsgBox "Matching Records Found"
  10. 'write whatevr code u want here
  11. Else
  12. MsgBox "Data not found"
  13. End If
  14. dr.Close()
  15. cn.Close()
Reply With Quote Quick reply to this message  
Join Date: Jan 2008
Posts: 97
Reputation: Estella is an unknown quantity at this point 
Solved Threads: 6
Estella's Avatar
Estella Estella is offline Offline
Junior Poster in Training

Re: Using RecordsAffected as a parameter

 
0
  #3
Jun 10th, 2008
thank for great suggestion
it help me much...
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the VB.NET Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC