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:
Public Sub Insert_RunsizeUPCs() Dim Command As SqlCommand Dim adapter As New SqlDataAdapter Dim dsin As New DataSet Dim i As Integer Dim sql As String Dim insertsql As String Dim Code_manip As Integer Dim New_Name As String Dim New_UPC As String Get_Max_Code() Code_manip = CInt(TxtCode.Text) Code_manip = Code_manip + 1 sql = "SELECT U_size FROM SIZERUNS WHERE U_run = " & TextBox2.Text 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 & ")" 'Connection = New SqlConnection(ConnectionString) Try Connection.Open() Command = New SqlCommand(sql, Connection) adapter.SelectCommand = Command adapter.Fill(dsin) adapter.Dispose() Command.Dispose() Connection.Close() For i = 0 To dsin.Tables(0).Rows.Count - 1 Code_manip = Code_manip + i New_Name = String.Concat(TextBox1.Text, dsin.Tables(0).Rows(i).Item(0)) New_UPC = UPC_Code_Manip() adapter.InsertCommand = New SqlCommand(insertsql, Connection) adapter.InsertCommand.ExecuteNonQuery() Next i Catch ex As Exception MsgBox("Can not open connection ! ") End Try End Sub




Reply With Quote