gpt4 book ai didi

c# - 存储过程或函数需要未提供的参数

转载 作者:可可西里 更新时间:2023-11-01 03:12:03 26 4
gpt4 key购买 nike

我试图通过调用存储过程将数据插入到 SQL Server 数据库中,但出现错误

*Procedure or function 'Insertion' expects parameter '@Emp_no', which was not supplied*

我的存储过程称为插入。我已经彻底检查过了,没有遗漏任何参数,我也用标签检查过。标签显示了值,但我不知道为什么会出现错误。

我的代码是

    try
{
SqlCommand cmd = new SqlCommand();
cmd.Parameters.Clear();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Insertion";
cmd.Connection = con;

if (rdb_Male.Checked)
{
int @Emp_no = Convert.ToInt32(txtbx_Empno.Text);
string @Emp_name = txtbx_Emp_Name.Text;
double @phone = Convert.ToDouble(txtbx_Phone.Text);
string @Email = txtbx_Email.Text;
string @Password = txtbx_Pwd.Text;
string @Gender = rdb_Male.Text;
DateTime @Dob = Convert.ToDateTime(dob);
string @Address = txtbx_Address.Text;
string @Designation = txtbx_Designation.Text;
string @Qualification = txtbx_Qual.Text;
double @Experience = Convert.ToDouble(txtbx_Exp.Text);
double @Salary = Convert.ToDouble(txtbx_Sal.Text);
DateTime @Doj = Convert.ToDateTime(doj);
}
else if (rdb_Female.Checked)
{
int @Emp_no = Convert.ToInt32(txtbx_Empno.Text);
string @Emp_name = txtbx_Emp_Name.Text;
double @phone = Convert.ToDouble(txtbx_Phone.Text);
string @Email = txtbx_Email.Text;
string @Password = txtbx_Pwd.Text;
string @Gender = rdb_Female.Text;
DateTime @Dob = Convert.ToDateTime(dob);
string @Address = txtbx_Address.Text;
string @Designation = txtbx_Designation.Text;
string @Qualification = txtbx_Qual.Text;
double @Experience = Convert.ToDouble(txtbx_Exp.Text);
double @Salary = Convert.ToDouble(txtbx_Sal.Text);
DateTime @Doj = Convert.ToDateTime(doj);
}

if (con.State==ConnectionState.Closed)
con.Open();

LABEL.Text = txtbx_Empno.Text;

cmd.ExecuteNonQuery();

lbl_Errormsg.Visible = true;
lbl_Errormsg.Text = "Record Inserted Successfully";

con.Close();
}

存储过程是

ALTER PROCEDURE dbo.Insertion
(
@Emp_no int,
@Emp_name varchar(30),
@phone numeric(10,0),
@Email varchar(30),
@Password varchar(10),
@Gender varchar(6),
@Dob date,
@Address varchar(100),
@Designation varchar(20),
@Qualification varchar(20),
@Experience numeric(4,2),
@Salary numeric(10,2),
@Doj date
)
AS
Begin
Insert into Register (Emp_no, Emp_name, phone, Email, Password, Gender, Dob, Address, Designation, Qualification, Experience, Salary, Doj)
Values(@Emp_no, @Emp_name, @phone, @Email, @Password, @Gender, @Dob, @Address, @Designation, @Qualification, @Experience, @Salary, @Doj)
End

请帮帮我。提前致谢。

最佳答案

只是提个醒,它可能会为人们省去很多时间来寻找灵魂。如果您遵循此处的建议,例如使用 AddWithValue 传递参数,并且您已验证所有内容,但仍然收到错误消息“未提供”,请检查您是否已设置命令对象的 CommandType 属性到 CommandType.StoredProcedure。

不设置此属性会产生相同的消息,相信我!希望对某人有所帮助。

关于c# - 存储过程或函数需要未提供的参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14640094/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com