i am getting the fallowing error in that query.
i somewhere use that statement
"INSERT INTO ROLES (userid,groupid) SELECT userid,groupid FROM users, groups WHERE username= '" + TextBox1.Text + "' AND name='" + a + "'";
works fine for me..
in the fallowing statement..
i want category id to be taken from another table categories id and selection is done on the bases of category name.
and the rest of the values are inserted from the textboxes.
no how to pass categoryid in the values field of the insert command.
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 + "'";
code form the dropdownlist:
SqlCommand cmd = new SqlCommand("SELECT * FROM ESK_Categories)", con"]));
cmd.Connection.Open();
SqlDataReader dr;
dr = cmd.ExecuteReader();
DropDownList1.DataSource = dr;
DropDownList1.DataValueField = "CateogoryName";
cmd.Connection.Close();
the error is as under:-
not insertedSystem.Data.SqlClient.SqlException: There are more columns in the INSERT statement than values specified in the VALUES clause. The number of values in the VALUES clause must match the number of columns specified in the INSERT statement. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) at System.Data.SqlClient.SqlCommand.RunExecuteNonQueryTds(String methodName, Boolean async) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Admin_Products.btnAdd_Click(Object sender, EventArgs e) Label