Try
Connections("sqldata").BeginTransaction() '开始事务
Dim cmd As new SQLCommand
cmd.C
'以下保存主表数据
cmd.CommandText = "INSERT INTO [tbl_出入库_主表] (单据编号,日期,填单员,单据类型,入库原因,备注) values (?,?,?,?,?,?)"
cmd.Parameters.Add("@单据编号",e.Form.Controls("TextBox1").value)
cmd.Parameters.Add("@日期",e.Form.Controls("DateTimePicker1").value)
cmd.Parameters.Add("@填单员",e.Form.Controls("TextBox2").value)
cmd.Parameters.Add("@单据类型",e.Form.Controls("TextBox3").value)
cmd.Parameters.Add("@入库原因",e.Form.Controls("TextBox4").value)
cmd.Parameters.Add("@备注",e.Form.Controls("TextBox5").value)
cmd.ExecuteNonQuery
'以下保存明细表数据
For Each r As Row In Tables("出入库_明细").Rows
'Dim spbh = r("商品编号") As Row '定义商品编号行
'Dim dw = r("单位") As Row
'Dim scrq r("生产日期") As Row
'Dim sh r("色号") As Row
'Dim shbz r("色号备注") As Row
'Dim sl r("数量") As Row
'Dim bz r("备注") As Row
'Dim kw r("库位") As Row
'Dim dj r("等级") As Row
Dim djbh As String =e.Form.Controls("TextBox3").value '
cmd.CommandText = "INSERT INTO [tbl_出入库_明细] (商品编号,单位,生产日期,色号,色号备注,数量,备注,库位,等级,单据编号) values (?,?,?,?,?,?,?,?,?,?)"
cmd.Parameters.Add("@商品编号",r("商品编号"))
cmd.Parameters.Add("@单位",r("单位"))
cmd.Parameters.Add("@生产日期",r("生产日期"))
cmd.Parameters.Add("@色号",r("色号"))
cmd.Parameters.Add("@色号备注",r("色号备注"))
cmd.Parameters.Add("@数量",r("数量"))
cmd.Parameters.Add("@备注", r("备注"))
cmd.Parameters.Add("@库位",r("库位"))
cmd.Parameters.Add("@等级",r("等级"))
cmd.Parameters.Add("@单据编号",djbh)
cmd.ExecuteNonQuery
Next
Connections("sqldata").Commit '提交事务,所有操作生效
MessageBox.show("保存成功")
Catch ex As Exception '如果出错
Connections("sqldata").Rollback() '回滚事务,撤销所有操作
MessageBox.Show("向服务器提交数据错误!","提示",MessageBoxButtons.OK)
End Try