Results 1 to 5 of 5

Thread: Help Constructing INSERT

Threaded View

  1. #1

    Thread Starter
    Member
    Join Date
    Sep 2011
    Posts
    34

    Help Constructing INSERT

    Im needing to construct an INSERT statement into a table called RUNSIZEUPCS using fields contained in hidden text boxes and a dataset to build out my record. I think I am close; however, I'm not sure about my insertsql statement since the New_UPC field is underlined in green. The following is the code that I have. Please help.
    vb.net Code:
    1. Public Sub Insert_RunsizeUPCs()
    2.         Dim Command As SqlCommand
    3.         Dim adapter As New SqlDataAdapter
    4.         Dim dsin As New DataSet
    5.         Dim i As Integer
    6.         Dim sql As String
    7.         Dim insertsql As String
    8.         Dim Code_manip As Integer
    9.         Dim New_Name As String
    10.         Dim New_UPC As String
    11.  
    12.         Get_Max_Code()
    13.         Code_manip = CInt(TxtCode.Text)
    14.         Code_manip = Code_manip + 1
    15.  
    16.         sql = "SELECT U_size FROM SIZERUNS WHERE U_run = " & TextBox2.Text
    17.         insertsql = "INSERT INTO RUNSIZEUPCS (Code,Name,U_item,U_size,U_upc) VALUES(Code_manip, New_Name, " & TextBox1.Text & ", " & dsin.Tables(0).Rows(i).Item(0) & New_UPC & ")"
    18.         'Connection = New SqlConnection(ConnectionString)
    19.  
    20.         Try
    21.             Connection.Open()
    22.             Command = New SqlCommand(sql, Connection)
    23.             adapter.SelectCommand = Command
    24.             adapter.Fill(dsin)
    25.             adapter.Dispose()
    26.             Command.Dispose()
    27.             Connection.Close()
    28.  
    29.             For i = 0 To dsin.Tables(0).Rows.Count - 1
    30.                 Code_manip = Code_manip + i
    31.                 New_Name = String.Concat(TextBox1.Text, dsin.Tables(0).Rows(i).Item(0))
    32.                 New_UPC = UPC_Code_Manip()
    33.                 adapter.InsertCommand = New SqlCommand(insertsql, Connection)
    34.                 adapter.InsertCommand.ExecuteNonQuery()
    35.             Next i
    36.         Catch ex As Exception
    37.             MsgBox("Can not open connection ! ")
    38.         End Try
    39.  
    40.  
    41.     End Sub
    Last edited by Hack; Oct 19th, 2011 at 08:52 AM. Reason: Added Highlight Tags

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