我有以下代碼:如何在文本框中顯示SQL查詢結果?
dbConnection cn = new dbConnection();
SqlCommand cmd = new SqlCommand();
protected void dropdown_student_SelectedIndexChanged(object sender, EventArgs e)
{
string StudentGUID = dropdown_student.SelectedValue;
cn.con.Open();
cn.cmd.Connection = cn.con;
cn.cmd.CommandText = "select SUM(Marks) AS 'Total' from Marksheet where StudentGUID = " + StudentGUID + " ";
dr = cn.cmd.ExecuteReader();
if (dr.HasRows)
{
while (dr.Read())
{
textbox_total.Text = dr["Total"].ToString();
}
cn.con.Close();
}
}
我要顯示在文本框中佔總分的價值,但它不工作。任何人都可以將我指向正確的方向嗎?
你得到任何錯誤或輸出得到dr [「Total」]? –
你在「textbox_total.Text」中獲得什麼價值? –
@ Aravind Sivam錯誤就是這樣的----'DB73801'附近語法不正確。並且該行是---- dr = cn.cmd.ExecuteReader(); –