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(); }
cmd.Parameter.AddWithValue("@compName", row["name"].ToString());
I tried to use command instead of cmd,but it still gives error.
Any ideas guys?