Must declare the scalar variable "@ID". RRS feed

  • Question




    hai, I'm getting a problem in this code can any one suggest me plz..........?

    DataTable dst = new DataTable();
                string Query = "Insert into TNET_Overlay(ID,OverLay,KeyRow,Col1,Col2,Col3,Col4,Col5,Col6,Col7,Col8,Col9,Col10,Col11,Col12)VALUES(@ID,@Overlay,@KeyRow,@Col1,@Col2,@Col3,@Col4,@Col5,@Col6,@Col7,@Col8,@Col9,@Col10,@Col11,@Col12)";
               // string Query = " SELECT * from TNET_Overlay O LEFT OUTER JOIN TNET_Station S ON O.Overlay=S.ID";
                DataSet ds = Utility.SFISConnection.ExecuteDataSet(Query);
                SqlDataAdapter da = new SqlDataAdapter(Query, connection);
                comboBox1.DisplayMember = "ID";
                comboBox1.ValueMember = "Location";
                ultraGridTT9.DataSource = ds;

    sateesh siriki

    • Moved by Barry Wang Thursday, July 19, 2012 5:39 AM Data related (From:.NET Framework Setup)
    Tuesday, July 17, 2012 3:37 PM


  • Is this your complete code for the INSERT command? Since you created parameters in your INSERT SQL statement, you also need to map those parameters to columns in your DataTable or to declare paramenets and provide values explicitly in your code.

    Val Mazur Microsoft MVP

    Friday, July 20, 2012 3:40 PM
  • In addition to what Val said about creating your parameters, you should be issuing a da.ExecuteNonQuery() rather than a da.Fill(ds), since you're trying to insert data, not fill the DataSet.

    ~~Bonnie Berent DeWitt [C# MVP]

    Saturday, July 21, 2012 4:00 PM

All replies