多查询执行中的问题 [英] problem in multiple query execution

查看:87
本文介绍了多查询执行中的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我第一次尝试执行sql查询


i was first trying to do that execute sql query


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 + "'";



但是这里有人告诉我将其分为两个查询.



but some one here tell me to split it into two queries..

query1="insert into ESKProducts (categoryid) select categoryid from ESK_Categories where categoryname=dropdownlist1.Text;

query="insert into ESK_Products(ProductName,ProductImage,UnitCost,Description) values('" + txtproname.Text + "','" + FileUpload1.FileName + "'," + txtproprice.Text + ",'" + txtprodesc.Text + "')


但我仍然无法实现我的结果.现在是什么问题


but i am still not able to fulfil my results. what is the problem now

推荐答案

您需要提供所有列才能进行插入.
第一个查询(query1)不包含所有列名,因此将不执行.

请注意,您没有在上面粘贴的代码中使用query1.可能与您不想在此处发布所有代码有关.
You need to provide all the columns in order to do an insert.
The first query (query1), does not contain all the column names and hence this will not execute.

Just as a note, you are not using query1 in the code you have pasted above. It could be to do with the fact that you don;t want to post all the code here.


请在提出有关问题的问题时解释诸如异常消息之类的症状.

在第二个插入中,您将陈述5列,但仅提供4个值,这就是您的问题.
Please when you ask a question about an issue explain the symptoms such as an exception message.

In the second insert you''re stating 5 columns but only supplying 4 values, that is your problem.


在您的第一个语句中,您已在执行SELECT之前关闭了VALUES,并且值应按INSERT的顺序排列; (此外,您的和"全都处于失衡状态...

In your first statement you have closed out the VALUES before executing the SELECT, and the values should line up on the order of the INSERT; (also, your " and '' where all out of balance......

string query1 = "INSERT INTO 
                           ESK_Products(CateogoryID,ProductName,ProductImage,UnitCost,Description) 
                VALUES( 
                          (select CategoryID 
                           from ESK_Categories 
                           where CategoryName='" + DropDownList1.Text + "'),'" + txtproname.Text + "','" + FileUpload1.FileName + "','" + txtproprice.Text + "','" + txtprodesc.Text + "');




可能更接近应有的状态.




Is probably more closer to what it should be.


这篇关于多查询执行中的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆