我目前正在使用windows窗體應用程序和sql server爲我的表編寫VB.net。我使用兩個組合框創建訂單,其中一個用於訂購材料類型,另一個用於名稱。在底部還有一個提交按鈕來運行SQL「Insert Into」代碼。材質組合框中填充了一個名爲「tbl.channel」的SQL表中的一列材質類型。該列下的每種材料類型都具有與該行關聯的零件號,ID和捆綁尺寸。我希望所有與該材料類型相關的信息寫入一個記錄所有訂單的新表格,用戶只需從組合框中選擇材料類型即可。如何使用「Select From」sql代碼將關聯的信息與該材料類型一起寫入新表中,以跟蹤所有訂購的材料?在VB.net中使用SQL查詢來撤銷adjacant行數據
Try
Dim connectionstring As String = Nothing
Dim connection As SqlConnection
Dim command As SqlCommand
Dim adapter As New SqlDataAdapter
Dim ds As New DataTable
Dim i As Integer = 0
Dim sql As String = Nothing
connectionstring = "DATA SOURCE = BNSigma\Core ; integrated security = true"
sql = "Select Channel, [Bundle Size], ID from Production.dbo.tblchannel"
connection = New SqlConnection(connstring)
connection.Open()
command = New SqlCommand(sql, connection)
adapter.SelectCommand = command
adapter.Fill(ds)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
Try
Using conn1 As New SqlConnection(connstring)
conn1.Open()
Using comm1 As SqlCommand = New SqlCommand("INSERT INTO Production.dbo.tbl (Channel, OrderedBy, Date1, BundleSize, ID) Values (@Channel, @Orderedby, @getdate(), @BundleSize, @ID)", conn1)
With comm1.Parameters
.AddWithValue("@Channel", CBChannel.SelectedValue)
.AddWithValue("@OrderedBy", CBName.SelectedValue)
.AddWithValue("@BundleSize", CBChannel.SelectedValue)
.AddWithValue("@ID", CBChannel.SelectedValue)
End With
End Using
End Using
Catch ex As Exception
MsgBox("Unable to make SQL connection")
MsgBox(ex.ToString)
End Try
對不起,大家好,我的代碼的最高位出了問題,那是一個try語句,後面是變暗的變量。 – Cheddar
你真的需要發佈如此龐大的代碼來解釋你的問題嗎? – Rahul
只是想給你所有的數據,我可以拉胡爾。 – Cheddar