返回首页

我第一次尝试做的,执行SQL查询

string query = "insert into ESK_Products(CateogoryID,ProductName,ProductImage,UnitCost,Description) values('" + txtproname.Text + "','" + FileUpload1.FileName + "'," + txtproprice.Text + ",'" + txtprodesc.Text + "') select CategoryID from ESK_Categories where CategoryName='" + DropDownList1.Text + "'";

但有些人告诉我,它分裂成两个查询......

{C}但我仍然不能够满足我的结果。现在的问题是什么

回答

评论会员:游客 时间:2012/02/04
。为了做一个插入,您需要提供的所有列第一次查询(查询1),不包含所有的列名,因此这将不执行。只是作为一个音符,你是不是在您粘贴上面的代码中使用的Query1。这可能是做的事实,你不要;不想在这里发表的所有代码。|西蒙邦Terkildsen:请解释的症状,如异常消息,有关问题的问题,当你问在第二个插入你说明5列,但只提供4个值,那是你的问题
DaveAuld
评论会员:游客 时间:2012/02/04
在您的第一条语句,你已经关闭之前执行SELECT的值,和值应该为了排队插入(同时,你的"和"所有失去平衡......codeprelang="cs"spanclass="code-keyword"string/spanquery1=spanclass="code-string""/spanspanclass="code-string"INSERTINTOESK_Products(CateogoryID,ProductName,ProductImage,UnitCost,Description)VALUES((selectCategoryIDfromESK_CategorieswhereCategoryName='"/span+DropDownList1.Text+spanclass="code-string""/spanspanclass="code-string"'),'"/span+txtproname.Text+spanclass="code-string""/spanspanclass="code-string"','"/span+FileUpload1.FileName+spanclass="code-string""/spanspanclass="code-string"','"/span+txtproprice.Text+spanclass="code-string""/spanspanclass="code-string"','"/span+txtprodesc.Text+spanclass="code-string""/spanspanclass="code-string"');/span/pre/code可能是更接近它应该是什么