943,910 Members | Top Members by Rank

Ad:
  • VB.NET Discussion Thread
  • Marked Solved
  • Views: 1035
  • VB.NET RSS
Jun 10th, 2008
0

Using RecordsAffected as a parameter

Expand Post »
VB.NET Syntax (Toggle Plain Text)
  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
VB.NET Syntax (Toggle Plain Text)
  1. IF Search.records affected = 0 THEN Insert records
  2. ELSE Display msgbox telling user that duplicate records aren't allowed.

Please Help...
Similar Threads
Reputation Points: 37
Solved Threads: 7
Junior Poster in Training
Estella is offline Offline
99 posts
since Jan 2008
Jun 10th, 2008
1

Re: Using RecordsAffected as a parameter

see this code :
VB.NET Syntax (Toggle Plain Text)
  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()
Reputation Points: 1182
Solved Threads: 392
Posting Sensei
Jx_Man is offline Offline
3,140 posts
since Nov 2007
Jun 10th, 2008
0

Re: Using RecordsAffected as a parameter

thank for great suggestion
it help me much...
Reputation Points: 37
Solved Threads: 7
Junior Poster in Training
Estella is offline Offline
99 posts
since Jan 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in VB.NET Forum Timeline: Need Help for Search function button
Next Thread in VB.NET Forum Timeline: running script





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC