|
-
Aug 14th, 2012, 01:14 PM
#1
Thread Starter
Member
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()
Last edited by Hack; Aug 14th, 2012 at 01:16 PM.
Reason: Added Highlight Tags
-
Aug 14th, 2012, 01:18 PM
#2
Re: Need Help WithVisual Baisc
Moved From The CodeBank (which is for sharing code rather than posting questions )
-
Aug 14th, 2012, 01:53 PM
#3
Re: Need Help WithVisual Baisc
What happens when you step through through the code.
-
Aug 14th, 2012, 01:55 PM
#4
Thread Starter
Member
Re: Need Help WithVisual Baisc
-
Aug 15th, 2012, 04:58 AM
#5
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|