SqlConnection connection = new SqlConnection(connString.ToString());
string select = "SELECT (CASE WHEN MAX(page_no) IS NULL THEN 1 ELSE MAX(page_no)+1 END) FROM dbo.BOOK";
string insert = "INSERT INTO dbo.BOOK (book_id,select) VALUES (121,4)";
SqlCommand sqlCommand = new SqlCommand(insert,connection);
insert.ExecuteNonQuery();
Here I got exception where the insert contains invalid string select.
Please tell me how assign sub query within the insert?
you cannot use a select statement like this
if you want to use a sub query it has to be in single statement
but in above statement you write in different different statement for selection
and insert query .
so
cmd.ExecuteNonquery()execute onlyinserttext statement so SQL engine unable to findSELECT(and SELECT is a Reserved keyword) so it gives you a errorif you go with subquery try this
sqlCommand.ExecuteNonQuery();