Results 1 to 5 of 5

Thread: Need Help WithVisual Baisc

  1. #1

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    47

    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:
    1. SQLSelect.Connection = SQLConnection
    2.                 SQLSelect.CommandText = "SELECT count(1) FROM [Inventory] WHERE  [TraceCode] ='" & TextBox1.Text & "'"
    3.  
    4.                 SQLConnection.Open()
    5.  
    6.                 Dim myReaders As SqlDataReader = SQLSelect.ExecuteReader()
    7.                 While myReaders.Read
    8.                     If myReaders.Item(0) = "0" Then
    9.  
    10.                         SQLinsert.Connection = SQLConnection
    11.  
    12.                         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 & "' )"
    13.  
    14.                         SQLinsert.Connection = SQLConnection
    15.                         myReaders.Close()
    16.                         SQLinsert.ExecuteNonQuery()
    17.                        TextBox1.Text = ""
    18.                       Exit Sub
    19.                    
    20.                     Else
    21.  
    22.                         TextBox1.Text = ""
    23.                         MessageBox.Show("Module Already Exist In Database")
    24.                         Exit Sub
    25.                         Focus()
    26.                     End If
    27.                 End While
    28.                 SQLConnection.Close()
    Last edited by Hack; Aug 14th, 2012 at 01:16 PM. Reason: Added Highlight Tags

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Need Help WithVisual Baisc

    Moved From The CodeBank (which is for sharing code rather than posting questions )

  3. #3
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    Re: Need Help WithVisual Baisc

    What happens when you step through through the code.

  4. #4

    Thread Starter
    Member
    Join Date
    Jun 2012
    Posts
    47

    Re: Need Help WithVisual Baisc

    What you mean?

  5. #5
    Wall Poster TysonLPrice's Avatar
    Join Date
    Sep 2002
    Location
    Columbus, Ohio
    Posts
    3,969

    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
  •  



Click Here to Expand Forum to Full Width