hi guys , i am doing a add book form of an admin panel in library automation at ASP.NET (C#).
I have a problem at declaring a variable , when i built the project there is no error or warning but when i run and clicked the add button the error comes.
the code is below
Code:
protected void btnInsert_Click(object sender, EventArgs e)
{
SqlConnection con = dbConnection.GetConnection();
SqlCommand command = new SqlCommand("select b_name from books where b_name=@name", con);
command.Parameters.AddWithValue("@name", txtBook.Text);
con.Open();
SqlDataReader rdr = command.ExecuteReader();
if (rdr.Read())
{
ltrlInf.Text = "";
ltrlInf.Text += "This book has been added before";
}
else
{
rdr.Close();
SqlCommand cmd2 = new SqlCommand("select c_id from categories where c_name=@catname", con);
cmd2.Parameters.AddWithValue("@catname", ddlCat.SelectedValue.ToString());
SqlDataReader rdr2 = cmd2.ExecuteReader();
while (rdr2.Read())
{
i = Int32.Parse(rdr2.GetValue(0).ToString());
}
SqlCommand cmd = new SqlCommand("insert into books (b_name,b_author,b_lang,b_page,c_id,b_stock,b_year,b_thumbnail,s_id) VALUES (@name,@author,@lang,@page,@cid@,@stock,@year,@thumbnail,@sid)", con);
cmd.Parameters.AddWithValue("@name", txtBook.Text);
cmd.Parameters.AddWithValue("@author", txtAuthor.Text);
cmd.Parameters.AddWithValue("@lang", txtLang.Text);
cmd.Parameters.AddWithValue("@page", txtPage.Text);
cmd.Parameters.AddWithValue("@cid",i);
cmd.Parameters.AddWithValue("@stock", txtStock.Text);
cmd.Parameters.AddWithValue("@year", txtYear.Text);
cmd.Parameters.AddWithValue("@thumbnail", ".\\" + "thumbs" + "\\" + FileUpload1.FileName);
cmd.Parameters.AddWithValue("@sid", ddlScat.SelectedValue.ToString());
rdr2.Close();
cmd.ExecuteNonQuery(); //ERROR COMES HERE ( Must declare the scalar variable "@cid@". )
ltrlInf.Text += "The book has been added";
con.Close();
}
}
i am waiting your answers...