返回首页

我做了这个简单的例子,但在数据库中插入数据使用过程,始终得到这个错误

Procedure or Function 'InsertInfo' expects parameter '@s_name', which was not supplied.

美中不足的是,表中插入数据,但显示错误!
HTML文件: -
{C}
代码(CS): -
publiv void insertData()

{

SqlConnection con = new SqlConnection(str_con);

con.Open();

SqlCommand cmd = new SqlCommand();

cmd.CommandText = "InsertInfo";

cmd.CommandType = CommandType.StoredProcedure;

cmd.Connection = con;

string a = Convert.ToString(txtName.Text);

int b = Convert.ToInt32(txtPhone.Text);

string c = txtDegree.Text;

cmd.Parameters.Add("@s_name", SqlDbType.VarChar).Value = a;

cmd.Parameters.Add("@s_phone", SqlDbType.Int).Value = b;

cmd.Parameters.Add("@s_degree", SqlDbType.VarChar).Value = c;

//cmd.Parameters.AddWithValue("@s_name", a);<------tried with these also

//cmd.Parameters.AddWithValue("@s_phone", b);

//cmd.Parameters.AddWithValue("@s_degree", c);

cmd.ExecuteNonQuery();<-------error points here

con.Close();

}

存储过程: -
{体C3}我向你乞求,请帮我找到错误。

回答

评论会员:thatraja 时间:2012/02/07
我知道了......在你的代码是没有问题的。在存储过程中删除最后一行:死:
{的C4}
评论会员:游客 时间:2012/02/07
爱德华・卢:这意味着你是不是传递值以@S_NAME的时,你调用存储过程。你需要通过SP的执行过程中的一个有效参数。的问候,爱德华
Abhiram嘉
评论会员:游客 时间:2012/02/07
我觉得不及格的价值@S_NAME调用存储过程在这里获得值{C5的}