1
我在更新C#中的数据库时出错。这里是代码:在数据库中更新时出错
string connectionstring = "server=AMAN;database=student;Integrated Security=True";
SqlConnection conn;
string Admission_no = txtAddmissionNo.Text;
SqlCommand cmd;
conn = new SqlConnection(connectionstring);
conn.Open();
string query = "update fees set [email protected]_fee, [email protected]_fee,[email protected]_fee ,[email protected]_money,[email protected]_fee,[email protected]_fee,[email protected]_fair,[email protected]_fee ,[email protected],[email protected]_fee,[email protected]_fine,[email protected]_dues,[email protected]_feemonth ,[email protected]_fee,[email protected]_fee,[email protected],[email protected],[email protected] where [email protected]_no";
cmd=new SqlCommand(query,conn);
cmd.Parameters.AddWithValue("@Admission_no", Admission_no);
cmd.Parameters.AddWithValue("@prospectues_fee", prospectues_fee);
cmd.Parameters.AddWithValue("@registration_fee", registration_fee);
cmd.Parameters.AddWithValue("@admission_fee", admission_fee);
cmd.Parameters.AddWithValue("@security_money", security_money);
cmd.Parameters.AddWithValue("@misslaneous_fee", misslaneous_fee);
cmd.Parameters.AddWithValue("@development_fee", development_fee);
cmd.Parameters.AddWithValue("@transport_fair", transport_fair);
cmd.Parameters.AddWithValue("@computer_fee", computer_fee);
cmd.Parameters.AddWithValue("@activity", activity);
cmd.Parameters.AddWithValue("@hostel_fee", hostel_fee);
cmd.Parameters.AddWithValue("@dely_fine", dely_fine);
cmd.Parameters.AddWithValue("@back_dues", back_dues);
cmd.Parameters.AddWithValue("@tution_fee", tution_fee);
cmd.Parameters.AddWithValue("@other_fee", other_fee);
cmd.Parameters.AddWithValue("@total", total);
cmd.Parameters.AddWithValue("@tution_feemonth", tution_feemonth);
cmd.Parameters.AddWithValue("@deposit", deposit_fee);
cmd.Parameters.AddWithValue("@dues", dues);
cmd = new SqlCommand(query, conn);
try
{
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
错误是@prospectues_fee
标量必须声明,我已经声明。
btw;有几个'IDisposable'对象,应该真的使用'使用'... –
对不起,它不工作 – Aman
“对不起,它不工作”; a:**完全**哪个“it”不工作,以及b:“不工作”是什么意思,**完全**? –