Click here to Skip to main content
15,900,378 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i was first trying to do that execute sql query


C#
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..

C#
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
Posted
Updated 2-Sep-11 0:38am
v2
Comments
Oshtri Deka 2-Sep-11 6:45am    
This question evolved from your other question (or vice versa).
Why don't you stick to your problem instead of asking almost the same thing two times?

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.
 
Share this answer
 
Comments
codegeekalpha 2-Sep-11 6:37am    
actually i want to post all the code here and i will do it lator.. i am in office now and left my laptop at home. because using laptop here is not allowed.
codegeekalpha 2-Sep-11 6:38am    
all codes are in my laptop
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.
 
Share this answer
 
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......

C#
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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900