private void button2_Click(object sender, EventArgs e)
{
// Open the connection using the connection string.
SqlConnection con = new SqlConnection(@"Data Source=WIN-6Q836P8JQ1C\oby;Initial Catalog=Etudiant;Integrated Security=True");
con.Open();
string sqlQuery = "INSERT INTO Abscence (CIN,Heure_debut,Heure_fin,Date)";
sqlQuery += "VALUES ('CIN', 'Heure_debut', 'Heure_fin', 'Date')";
// Insert into the Sql table. ExecuteNonQuery is best for inserts.
using (SqlCommand com = new SqlCommand(sqlQuery, con))
{
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
com.Parameters.AddWithValue("CIN", dataGridView1.Rows[i].Cells["CIN"].Value);
com.Parameters.AddWithValue("Heure_debut", dataGridView1.Rows[i].Cells["column1"].Value);
com.Parameters.AddWithValue("Heure_fin",dataGridView1.Rows[i].Cells["column2"].Value);
com.Parameters.AddWithValue("Date", dateTimePicker1.Text);
}
com.ExecuteNonQuery();
com.Parameters.Clear();
con.Close();
}
}
}
请帮助我,这是我的学士学位项目如何在这段代码声明标量变量“@CIN”
参数名称应以'@'开头。 – Blorgbeard 2015-03-31 21:05:42
我不明白这种类型的评论'请帮助我这是我的学士学位项目'。为什么你认为我们应该帮助你。对于前者,我不希望有一个队友(也许在不久的将来)谁不能解决这个问题。 – EZI 2015-03-31 21:12:07