Need Help WithVisual Baisc
I really need help with a query in Visual basic. I have in program that insert data into a sql table, but Im trying to duplicate the data. Basically tring to make the messagebox pop up if I try insert a data into the table, which is already in the table. Can someone please help. I provided my code below
vb Code:
SQLSelect.Connection = SQLConnection
SQLSelect.CommandText = "SELECT count(1) FROM [Inventory] WHERE [TraceCode] ='" & TextBox1.Text & "'"
SQLConnection.Open()
Dim myReaders As SqlDataReader = SQLSelect.ExecuteReader()
While myReaders.Read
If myReaders.Item(0) = "0" Then
SQLinsert.Connection = SQLConnection
SQLinsert.CommandText = "INSERT INTO Inventory ([SerialNumber], [PartNumber], [VINNumber], [Status], [ProcessDate], [AllocatedDate], [RackGroup], [TraceCode], [ProcessSequence]) values ('" & TextBox2.Text & "','" & TextBox3.Text & "', '" & TextBox4.Text & "','" & TextBox5.Text & "', '" & TextBox6.Text & "','" & TextBox7.Text & "','" & TextBox8.Text & "', '" & TextBox9.Text & "','" & TextBox10.Text & "' )"
SQLinsert.Connection = SQLConnection
myReaders.Close()
SQLinsert.ExecuteNonQuery()
TextBox1.Text = ""
Exit Sub
Else
TextBox1.Text = ""
MessageBox.Show("Module Already Exist In Database")
Exit Sub
Focus()
End If
End While
SQLConnection.Close()
Re: Need Help WithVisual Baisc
Moved From The CodeBank (which is for sharing code rather than posting questions :) )
Re: Need Help WithVisual Baisc
What happens when you step through through the code.
Re: Need Help WithVisual Baisc
Re: Need Help WithVisual Baisc
Put a breakpoint at the beginning of your code and then step through it one line at a time and see how the logic is flowing. If you don't know what I mean by that check out this link.
http://www.homeandlearn.co.uk/net/nets5p6.html