3
Reply

No definition for parameter error

sam

sam

Sep 16 2010 11:19 PM
1.8k
Hi.
I have a code where it will store values from textbox to gridview temporarily without sending to database.
Now i have created a button,trying to send the values in temporary gridview to database.
Here's the cs code :
 protected void BtnSendToDatabase_Click(object sender, EventArgs e)
        {
            foreach (DataRow row in dt.Rows)
            {
                Console.WriteLine(row["name"].ToString());
            }

            SqlCommand cmd = new SqlCommand();
            cmd.CommandText = "INSERT INTO Table1 (Company_Name) VALUES (@compName)";
            cmd.Parameters.AddWithValue("@compName", TxtName.Text);
           
            foreach (DataRow row in dt.Rows)
            {
                cmd.Parameter.AddWithValue("@compName", row["name"].ToString());
                cmd.ExecuteNonQuery();
            }

            cmd.Dispose();
            conn.Close();
            conn.Dispose();
        }

But i'm getting this error:
CS1061: 'System.Data.SqlClient.SqlCommand' does not contain a definition for 'Parameter' and no extension method 'Parameter' accepting a first argument of type 'System.Data.SqlClient.SqlCommand' could be found (are you missing a using directive or an assembly reference?)
Source error:
cmd.Parameter.AddWithValue("@compName", row["name"].ToString());

I tried to use command instead of cmd,but it still gives error.

Any ideas guys?



Answers (3)