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