Results 1 to 5 of 5

Thread: Need Help WithVisual Baisc

  1. #1
    Member
    Join Date
    Jun 12
    Posts
    41

    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
    Super Moderator Hack's Avatar
    Join Date
    Aug 01
    Location
    Searching for mendhak
    Posts
    58,283

    Re: Need Help WithVisual Baisc

    Moved From The CodeBank (which is for sharing code rather than posting questions )
    Please use [Code]your code goes in here[/Code] tags when posting code.
    When you have received an answer to your question, please mark it as resolved using the Thread Tools menu.
    Before posting your question, did you look here?
    Got a question on Linux? Visit our Linux sister site.
    I dont answer coding questions via PM or EMail. Please post a thread in the appropriate forum section.

    Creating A Wizard In VB.NET
    Paging A Recordset
    What is wrong with using On Error Resume Next
    Good Article: Language Enhancements In Visual Basic 2010
    Upgrading VB6 Code To VB.NET
    Microsoft MVP 2005/2006/2007/2008/2009/2010/2011/2012/Defrocked

  3. #3
    Frenzied Member
    Join Date
    Sep 02
    Location
    Columbus, Ohio
    Posts
    1,808

    Re: Need Help WithVisual Baisc

    What happens when you step through through the code.

  4. #4
    Member
    Join Date
    Jun 12
    Posts
    41

    Re: Need Help WithVisual Baisc

    What you mean?

  5. #5
    Frenzied Member
    Join Date
    Sep 02
    Location
    Columbus, Ohio
    Posts
    1,808

    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
  •