![]() |
| | #1 |
| Registered User Join Date: Aug 2008
Posts: 71
| 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();
}
}
|
| Aga^^ is offline | |
| | #2 |
| &TH of undefined behavior Join Date: Aug 2001
Posts: 5,261
| Havent run your code but dont you thing that "@cid@" is different from "@cid"? Look at your sql
__________________ "If A is success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping your mouth shut." Albert Einstein (1879 - 1955) Board Rules |
| Fordy is offline | |
| | #3 |
| Registered User Join Date: Aug 2008
Posts: 71
| upsss i am sleepy and tired.Thanks a lot Fordy |
| Aga^^ is offline | |
| | #4 |
| Registered User Join Date: Jul 2009
Posts: 10
| wow dats hard to me (((blurrr))) |
| zeetaQ53 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| life cycle of exception object | George2 | C++ Programming | 43 | 02-13-2008 07:50 AM |
| Problem with the exception class in MINGW | indigo0086 | C++ Programming | 6 | 01-20-2007 01:12 PM |
| Declaring an variable number of variables | Decrypt | C++ Programming | 8 | 02-27-2005 04:46 PM |
| float/double variable storage and precision | cjschw | C++ Programming | 4 | 07-28-2003 06:23 PM |
| Beginner question | Tride | C Programming | 30 | 05-24-2003 08:36 AM |