Hi,
I am facing problem in this piece of code.
Actually this is the coding of a form which is used to add new book in database.These fields are going to add in the book table.
like BOOK ID , BOOK TITLE , AUTHOR NAME nad so on
But whenever I run this code .It gives error on line cmd.ExecuteNonQuery();
There are two possible reasons for this error thet either my connection string is wrong or my Insert query is wrong.
But with the same conn string I ve run other forms and it didnt give any error.
And i ve also checked my insert query in SQL. It ran perfectly alright.
Please help me out in finding out error ion this code.
*************************************************************
private
void btnAddBook_Click(object sender, System.EventArgs e)
{
string strBookId=txtBookId.Text;
string strTitle =txtBookTitle.Text;
string strAuthor_Id1=txtAuthorId1.Text;
string strAuthor_Id2=txtAuthorId2.Text;
string strEdition=txtBookEdition.Text;
string strCategory=txtBookCategory.Text;
string strQuery = "Insert into BOOK values("+ strBookId + ", '" + strTitle + "' ," + strAuthor_Id1 + " , "+ strAuthor_Id2 + " ,' "+strEdition +" ' , ' "+strCategory+ " ') ";
OleDbConnection conn =
new OleDbConnection("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=LMS;Data Source=abs");
conn.Open();
OleDbCommand cmd =
new OleDbCommand(strQuery,conn);
ERROR=============> cmd.ExecuteNonQuery();
conn.Close();
}
**********************************************************
waiting for your reply
thanks
Enter your message below
Sign in or Join us (it's free).