本文介绍了system.data.dll附加信息中发生了'system.data.sqlclient.sqlexception'类型的未处理异常:必须声明标量变量“@ name”。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  private   void  button2_Click(对象发​​件人,EventArgs e)
{
字符串 insert = 插入[dbo]。[Student_Info]值(@ Name,@ Address,@ FatherName,@ Class);
SqlCommand cmd = new SqlCommand(insert,con);
SqlParameter [] prm = new SqlParameter [ 4 ];
prm [ 0 ] = new SqlParameter( @ Name,SqlDbType.VarChar);
prm [ 0 ]。Value = textBox9.Text;

prm [ 1 ] = new SqlParameter( @ Address,SqlDbType.VarChar);
prm [ 1 ]。Value = textBox8.Text;

prm [ 2 ] = new SqlParameter( @ FatherName,SqlDbType.VarChar);
prm [ 2 ]。Value = textBox7.Text;
prm [ 3 ] = new SqlParameter( @ Class,SqlDbType.VarChar);
prm [ 3 ]。Value = textBox6.Text;

con.Open();
cmd.ExecuteNonQuery();
con.Close();
MessageBox.Show( Inserted Data);
}





我的尝试:



请帮帮我,我有这个需要声明标量变量的错误

解决方案




private void button2_Click(object sender, EventArgs e)
{
   string insert ="insert into [dbo].[Student_Info] values (@Name,@Address,@FatherName,@Class)";
   SqlCommand cmd = new SqlCommand(insert, con);
   SqlParameter[] prm = new SqlParameter[4];
   prm[0] = new SqlParameter("@Name", SqlDbType.VarChar);
   prm[0].Value = textBox9.Text;

   prm[1] = new SqlParameter("@Address", SqlDbType.VarChar);
   prm[1].Value = textBox8.Text;

   prm[2] = new SqlParameter("@FatherName", SqlDbType.VarChar);
   prm[2].Value = textBox7.Text;
   prm[3] = new SqlParameter("@Class", SqlDbType.VarChar);
   prm[3].Value = textBox6.Text;

   con.Open();
   cmd.ExecuteNonQuery();
   con.Close();
   MessageBox.Show("Inserted Data");
}



What I have tried:

please help me i have this erroe that want must be declare scalar variable

解决方案




这篇关于system.data.dll附加信息中发生了'system.data.sqlclient.sqlexception'类型的未处理异常:必须声明标量变量“@ name”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-30 02:47