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 belowvb 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()


Reply With Quote
)

