|
-
Oct 19th, 2011, 08:48 AM
#1
Thread Starter
Member
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:
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
Last edited by Hack; Oct 19th, 2011 at 08:52 AM.
Reason: Added Highlight Tags
-
Oct 19th, 2011, 08:55 AM
#2
Re: Help Constructing INSERT
Moved From The CodeBank (which is for sharing code rather than posting questions )
-
Oct 19th, 2011, 09:34 AM
#3
Lively Member
Re: Help Constructing INSERT
Code:
Dim New_UPC As String
:
:
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)
you declared the variable alright but forgot to initialized/put value in it before using. try to put something in New_UPC prior to using it.
Last edited by Hack; Oct 19th, 2011 at 11:09 AM.
-
Oct 19th, 2011, 10:56 AM
#4
Thread Starter
Member
Re: Help Constructing INSERT
Thank you for looking at it. I figured out what was going on just a bit ago.
-
Oct 19th, 2011, 11:10 AM
#5
Re: Help Constructing INSERT
Please post your solution. It could help others with the same or similar problem.
Also, as a newer member I ask that if you consider your question to be resolved please help us out by pulling down the Thread Tools menu and clicking the Mark Thread Resolved menu item. That will let everyone know that you have your answer.
Thank you.
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
|