question

abdelrahmanmostafa-2491 avatar image
0 Votes"
abdelrahmanmostafa-2491 asked JackJJun-MSFT commented

i keep getting this error "Must declare the scalar variable"

//>>>>> this is the connection to sql

public partial class Form1 : Form
{

     OleDbConnection con_sql = new OleDbConnection("Provider = sqloledb; Server=IT1038-109\\SQL_ABDELRAHMAN;Database=nana_db;Trusted_Connection=yes;");

//>>>>> this is the error button

private void button5_Click(object sender, EventArgs e)
{

         con_sql.Open();
         OleDbCommand cmd1 = con_sql.CreateCommand();

            

         cmd1.CommandText = "select id,name,job,salary from info where id=@drr ";



//>>>>>>>>>>>>>>problem here
cmd1.Parameters.AddWithValue("@drr", textbox7.text);

         OleDbDataReader reader5;
         reader5 = cmd1.ExecuteReader();

         if (reader5.Read())
         {
             textBox3.Text = reader5["id"].ToString();
             textBox4.Text = reader5["name"].ToString();
             textBox5.Text = reader5["job"].ToString();
             textBox6.Text = reader5["salary"].ToString();
         }
         else
         {
             MessageBox.Show("wait ..");
         }

         MessageBox.Show("Record Submitted", "Congrats");
         con.Close();
     }

windows-forms
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.


Maybe the textbox7 was empty?


0 Votes 0 ·

@abdelrahmanmostafa-2491, is any update?

 Must declare the scalar variable"

Which variable do you mean?


0 Votes 0 ·

0 Answers