【发布时间】:2015-09-23 07:51:57
【问题描述】:
我使用选择查询来读取值,然后使用下面的代码通过一些更新重新插入(不更新)它们。 我正在尝试使用插入运行此查询并同时选择,但没有工作,我没有出现任何错误。
string docdetls = "Insert into DocDetls (DocStatus, DocType, DocNo,SeqNo,ItemCode,Quantity,Price,Disc,DiscAmount,VAT,ExpDate)"+
"(SELECT 2 as DocStatus, DocType, @newdocno as DocNo,SeqNo,ItemCode,Quantity,Price,Disc,DiscAmount,VAT,ExpDate FROM docdetls where DocStatus=@stat and DocNo=@docno)";
MySqlCommand cmd4 = new MySqlCommand(docdetls, con);
cmd4.Parameters.AddWithValue("stat", "1");
cmd4.Parameters.AddWithValue("newdocno", DocNoTxtBox.Text);
cmd4.Parameters.AddWithValue("DocNo",no );
con.Open();
cmd4.ExecuteNonQuery();
con.Close();
如果我在具有某些值的 mysql 工作台上运行相同的查询是有效的。 这可能吗?我怎样才能做到这一点?
回答后更新
string docdetls = "Insert into DocDetls (DocStatus, DocType, DocNo,SeqNo,ItemCode,Quantity,Price,Disc,DiscAmount,VAT,ExpDate)"+
"(SELECT 2 as DocStatus, DocType, @newdocno as DocNo,SeqNo,ItemCode,Quantity,Price,Disc,DiscAmount,VAT,ExpDate FROM docdetls where DocStatus=@stat and DocNo=@docno)";
MySqlCommand cmd4 = new MySqlCommand(docdetls, con);
cmd4.Parameters.AddWithValue("stat", "1");
//cmd4.Parameters.AddWithValue("newdocno", DocNoTxtBox.Text);
cmd4.Parameters.AddWithValue("DocNo",no );
cmd4.Parameters.Add("@newdocno", MySqlDbType.Int16).Value = DocNoTxtBox.Text;
con.Open();
cmd4.ExecuteNonQuery();
con.Close();
还是不行..
【问题讨论】:
-
问题是关于插入 with 选择。与插入和选择无关。