这是我得到的错误 - “过程或函数'submitrecord'期望参数'@empcode',这是未提供的。” [英] This is the error I'm getting- "Procedure or function 'submitrecord' expects parameter '@empcode', which was not supplied."

查看:131
本文介绍了这是我得到的错误 - “过程或函数'submitrecord'期望参数'@empcode',这是未提供的。”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

webform.aspx.cs:

webform.aspx.cs:

SqlConnection conn = new SqlConnection(System.Web.Configuration.WebConfigurationManager.ConnectionStrings["DBConnectionString"].ConnectionString);

conn.Open();
SqlCommand cmd = new SqlCommand();
cmd.Parameters.Add("@empcode", SqlDbType.VarChar).Value = Convert.ToString(TextBox1.Text);
cmd.Parameters.Add("@empname", SqlDbType.VarChar).Value = TextBox2.Text;

cmd = new SqlCommand("submitrecord", conn);
cmd.CommandType = CommandType.StoredProcedure;

cmd.ExecuteNonQuery(); //error shown on this line

conn.Close();



存储过程 - 提交记录:


Stored procedure-submitrecord:

CREATE PROCEDURE submitrecord

@empcode varchar(50),
@empname varchar(50),
@sname varchar(50),
@location varchar(50),
@deptname varchar(50)
AS
insert into acyutaTB(emp_code,emp_name,sname,location,dept_name) values(@empcode,@empname,@sname,@location,@deptname)
GO

推荐答案

嗯...

Um...
SqlCommand cmd = new SqlCommand();
cmd.Parameters.Add("@empcode", SqlDbType.VarChar).Value = Convert.ToString(TextBox1.Text);
cmd.Parameters.Add("@empname", SqlDbType.VarChar).Value = TextBox2.Text;

cmd = new SqlCommand("submitrecord",conn);
cmd.CommandType = CommandType.StoredProcedure;

所以...你创建一个命令,将参数添加到它,然后扔掉它来创建一个新的?为什么?

试试这个:

So...You create a Command, add the parameters to it, and then throw it away to create a new one? Why?
Try this:

SqlCommand cmd = new SqlCommand("submitrecord",conn);
cmd.Parameters.Add("@empcode", SqlDbType.VarChar).Value = Convert.ToString(TextBox1.Text);
cmd.Parameters.Add("@empname", SqlDbType.VarChar).Value = TextBox2.Text;
cmd.CommandType = CommandType.StoredProcedure;

或者更好的这个:

Or better this:

SqlCommand cmd = new SqlCommand("submitrecord",conn);
cmd.Parameters.AddWithValue("@empcode", TextBox1.Text);
cmd.Parameters.AddWithValue("@empname", TextBox2.Text);
cmd.CommandType = CommandType.StoredProcedure;


这篇关于这是我得到的错误 - “过程或函数'submitrecord'期望参数'@empcode',这是未提供的。”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆