我如何通过来自另一个 table 的特定字段的 select 数据插入 table
how can i insert into table via select data from another table for specific field
我正在使用 OLEDB 连接到 Microsoft Access 数据库。我想在 "tblItemMst" 中的 "tblCallibrationNewGauge" 中插入 "ItemDesc" 字段数据,以及另一个字段,例如从用户那里获取的 "ItemCode"、"Customer"、"Quantity" 值。下面是我的代码:
If con.State = ConnectionState.Open Then
con.Close()
con.Open()
Else
con.Open()
End If
Dim cmd As New OleDbCommand("Insert Into tblCallibrationNewGauge(ItemCode,ItemDesc,Customer,Quantity)VALUES('" + partCode.Text.ToString() + "',(Select ItemDesc from tblItemMst where ItemCode='" + partCode.Text.ToString() + "'),'" + cmb_customer.Text.ToString() + "','" + quantity.Text.ToString() + "'",con)
If cmd.ExecuteNonQuery() Then
MessageBox.Show("Data Inserted")
End If
con.Close()
我遇到了异常错误。
有可能这样做吗?要么
有什么方法可以将数据插入 table 中,其中某些字段取自其他 table 而某些字段取自 winform Control?
提前致谢。
像这样更改命令文本:
Dim cmd As New OleDbCommand("Insert Into tblCallibrationNewGauge( ItemCode,ItemDesc,Customer,Quantity) SELECT '" + partCode.Text.ToString() + "', ItemDesc,'" + cmb_customer.Text.ToString() + "','" + quantity.Text.ToString() + "' from tblItemMst where ItemCode='" + partCode.Text.ToString() + "'",con)
我正在使用 OLEDB 连接到 Microsoft Access 数据库。我想在 "tblItemMst" 中的 "tblCallibrationNewGauge" 中插入 "ItemDesc" 字段数据,以及另一个字段,例如从用户那里获取的 "ItemCode"、"Customer"、"Quantity" 值。下面是我的代码:
If con.State = ConnectionState.Open Then
con.Close()
con.Open()
Else
con.Open()
End If
Dim cmd As New OleDbCommand("Insert Into tblCallibrationNewGauge(ItemCode,ItemDesc,Customer,Quantity)VALUES('" + partCode.Text.ToString() + "',(Select ItemDesc from tblItemMst where ItemCode='" + partCode.Text.ToString() + "'),'" + cmb_customer.Text.ToString() + "','" + quantity.Text.ToString() + "'",con)
If cmd.ExecuteNonQuery() Then
MessageBox.Show("Data Inserted")
End If
con.Close()
我遇到了异常错误。 有可能这样做吗?要么 有什么方法可以将数据插入 table 中,其中某些字段取自其他 table 而某些字段取自 winform Control?
提前致谢。
像这样更改命令文本:
Dim cmd As New OleDbCommand("Insert Into tblCallibrationNewGauge( ItemCode,ItemDesc,Customer,Quantity) SELECT '" + partCode.Text.ToString() + "', ItemDesc,'" + cmb_customer.Text.ToString() + "','" + quantity.Text.ToString() + "' from tblItemMst where ItemCode='" + partCode.Text.ToString() + "'",con)