By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,157 Members | 1,001 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,157 IT Pros & Developers. It's quick & easy.

VB Check if record exist

P: 1
Hi all,

i have this problem;

- i want to check if the serial number is exist inside the database, and if its exist, i want to check one of the column name called "FLAG" if its equal to 1 or 0. can someone suggest me on how can i do the code?

FYI, my current code is ;

Expand|Select|Wrap|Line Numbers
  1. Private Sub SRN_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles SRN.KeyUp
  2.         If e.KeyCode = Keys.Enter Then
  3.             Dim myconnect As New SqlClient.SqlConnection
  4.             myconnect.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\User\My Documents\ETdb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
  5.             Dim mycommand As SqlClient.SqlCommand = New SqlClient.SqlCommand()
  6.             mycommand.Connection = myconnect
  7.  
  8.             mycommand.CommandText = "INSERT INTO T3 (SRN, SESSION, EVENT_NAME, SYSTIME, SYSDATE, FLAG) VALUES (' " & Replace(SRN.Text, vbNewLine, "") & "' ,'" & SESSION.Text & " ',' " & EVENT_NAME.Text & "','" & SYSTIME.Text & " ','" & SYSDATE.Text & "','" & "1" & "')"
  9.  
  10.             myconnect.Open()
  11.             mycommand.ExecuteNonQuery()
  12.             myconnect.Close()
  13.             SRN.Text = ""
  14.         End If
  15.     End Sub
----

There is nothing wrong with this code, i manage to add new record, but i need your help to do one more function which is, if the record is exist then i no need to add new record but only to change the value of the "FLAG" from 1 -> 0 or the other way around. i really need your help. thank you.
Jan 15 '15 #1
Share this Question
Share on Google+
1 Reply


Frinavale
Expert Mod 5K+
P: 9,731
For a basic overview, please check out the How to Use a DataBase in Your Program article.

_Frinny
Jan 15 '15 #2

Post your reply

Sign in to post your reply or Sign up for a free account.