我在使用sql server2008存儲數字,百分比等數據庫的winforms上創建一個標記表..但是,我在使用以下代碼時遇到了上述異常錯誤:「真實」附近的語法不正確。關鍵字'where'的語法不正確
private void button1_Click(object sender, EventArgs e)
{
float a = float.Parse(textBox1.Text);
float b = float.Parse(textBox2.Text);
float c = float.Parse(textBox3.Text);
float d = float.Parse(textBox4.Text);
float f = float.Parse(textBox5.Text);
float g = (a + b + c + d + f);
float h = (g/500) * 100;
label11.Text = Convert.ToString((g));
label14.Text = Convert.ToString(h + "%");
label11.Visible = label14.Visible = true;
SqlConnection con = new SqlConnection("Data Source=Emmad-PC;Initial Catalog=SchoolManagement;User ID=sa;Password=lenovo");
SqlCommand j =new SqlCommand("Insert into Marksheet(RollNo, English, Math, Science, PSt, Islamiat, Total, Percentage) where values(@ROLL NO, @English, @Math, @Science, @Pakistan Studies, @Islamiat, @Total, @Percentage",con);
j.Parameters.AddWithValue("@ROLL NO",float.Parse(textBox6.Text));
j.Parameters.AddWithValue("@English", float.Parse(textBox1.Text));
j.Parameters.AddWithValue("@Math", float.Parse(textBox2.Text));
j.Parameters.AddWithValue("@Science", float.Parse(textBox3.Text));
j.Parameters.AddWithValue("@Pakistan Studies", float.Parse(textBox4.Text));
j.Parameters.AddWithValue("@Islamiat", float.Parse(textBox5.Text));
j.Parameters.AddWithValue("@Total",Convert.ToString(label11.Text));
j.Parameters.AddWithValue("@Percentage",Convert.ToString(label14.Text));
con.Open();
j.ExecuteNonQuery();
con.Close();
}
您的建議將是非常可觀的:)
正如其他人所說的,你應該刪除'where',你寫什麼意圖? – HoneyBadger
除了其他意見,你還有其他一些問題在這裏。首先是你的桌子看起來非常不規範。其次是你正在使用花車存儲成績。浮點數據類型是近似值,在精確值很重要時不應使用。在這種情況下,int或numeric可能是更好的選擇。最後但並非最不重要的一點是,您的Total列應該是一個計算列,因此您不會將該值與其他列值不同步。 –