过程或函数'InsertInfo'需要参数'@s_name',这是未提供的。 [英] Procedure or Function 'InsertInfo' expects parameter '@s_name', which was not supplied.

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

问题描述

我创建了这个使用过程在数据库中插入数据的简单示例,但始终收到此错误

过程或函数'InsertInfo'需要参数'@s_name',这是未提供的。



Catch是数据插入表但显示错误!

HTML文件
: -

 <   div  >  
< asp :标签 runat = 服务器 > 名称< / asp:标签 >
< asp:TextBox runat = 服务器 ID = txtName > < / asp:TextBox > < br / >
< asp:标签 runat = 服务器 > 电话号码< / asp:Label >
< asp: TextBox runat = < span class =code-keyword> server
ID = txtPhone > < / asp:TextBox > < br / >
< asp:Label runat = 服务器 > 学位:< / asp:标签 >
< asp:TextBox runat = 服务器 ID = txtDegree > < / asp:TextBox > < br / >
< as p:按钮 runat = 服务器 ID = btnSubmit 文本 = 提交 onclick = btnSubmit_Click / >
< asp:Button runat = 服务器 ID = btnEdit 文字 = 编辑 / >
< / div >





代码(.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);& lt; ------尝试使用这些
//cmd.Parameters.AddWithValue(\"@s_phone ,b);
//cmd.Parameters.AddWithValue(\"@s_degree,c);
cmd.ExecuteNonQuery();& lt; -------错误点在这里
con.Close();
}





存储过程: -

  set   ANSI_NULLS   ON  
set QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo]。[InsertInfo]

@ s_name varchar 300 ),
@ s_phone int
@ s_degree varchar 300

as
insert into info(s_ name,s_phone,s_degree) values @ s_name @ s_phone @ s_degree
exec InsertInfo



我求求你,请帮我找到错误。

解决方案

我明白了。你的代码没有问题。删除存储过程中的最后一行:dead:

  set   ANSI_NULLS   ON  
set QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo]。[InsertInfo]

@s_name varchar 300 ),
@ s_phone int
@ s_degree varchar 300

as
插入 进入 info(s_name,s_phone, s_degree) @ s_name @ s_phone @ s_degree
exec InsertInfo - --------本行


这意味着在调用存储过程时,您没有将值传递给 @s_name 。你需要在SP执行期间传递一个有效的参数。



问候,

Eduard


I认为在调用存储过程时没有传递Value @s_name



这里得到的价值

字符串a = Convert.ToString (txtName.Text); 


I made this simple example of inserting data in DB using procedure but always getting this error

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


Catch is that data is inserted in the table but error is shown!
HTML file
:-

<div>
    <asp:Label runat=server>Name</asp:Label>
    <asp:TextBox runat=server ID="txtName"></asp:TextBox><br />
    <asp:Label runat=server>Phone No.</asp:Label>
    <asp:TextBox runat=server ID="txtPhone"></asp:TextBox><br />
    <asp:Label runat=server>Degree in:</asp:Label>
    <asp:TextBox runat=server ID="txtDegree"></asp:TextBox><br />
    <asp:Button runat=server ID="btnSubmit" Text="Submit" onclick="btnSubmit_Click"/>
    <asp:Button runat=server ID="btnEdit" Text="Edit" />
    </div>



Code(.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);&lt;------tried with these also
//cmd.Parameters.AddWithValue("@s_phone", b);
//cmd.Parameters.AddWithValue("@s_degree", c);
cmd.ExecuteNonQuery();&lt;-------error points here
con.Close();
}



Stored procedure:-

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[InsertInfo]
(
	@s_name varchar(300),
	@s_phone int,
	@s_degree varchar(300)
)
as
insert into info(s_name,s_phone,s_degree) values(@s_name,@s_phone,@s_degree)
exec InsertInfo


I beg to you, please help me find the error.

解决方案

I got it.. There is no issue in your code. Remove the last line in your stored procedure :dead:

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[InsertInfo]
(
@s_name varchar(300),
@s_phone int,
@s_degree varchar(300)
)
as
insert into info(s_name,s_phone,s_degree) values(@s_name,@s_phone,@s_degree)
exec InsertInfo----------THIS LINE


This means you are not passing a value to @s_name when you are calling the stored procedure. You need to pass a valid parameter during SP execution.

Regards,
Eduard


I think not passing the Value @s_name when calling stored Procedure

Here getting Value

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


这篇关于过程或函数'InsertInfo'需要参数'@s_name',这是未提供的。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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