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
- Private Sub SRN_KeyUp(ByVal sender As System.Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles SRN.KeyUp
- If e.KeyCode = Keys.Enter Then
- Dim myconnect As New SqlClient.SqlConnection
- myconnect.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Documents and Settings\User\My Documents\ETdb.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
- Dim mycommand As SqlClient.SqlCommand = New SqlClient.SqlCommand()
- mycommand.Connection = myconnect
- 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" & "')"
- myconnect.Open()
- mycommand.ExecuteNonQuery()
- myconnect.Close()
- SRN.Text = ""
- End If
- 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.