在ido.net和C#中将多个参数传递给sql过程的问题 [英] Problem for passing multiple parameters to sql procedure in ido.net and c#

查看:97
本文介绍了在ido.net和C#中将多个参数传递给sql过程的问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


例如:

创建过程findgoodStudent
@mark int,
@city nvarchar(50)

从学生中选择S_id
在最小和最大之间的@ city = S_city和@mark


我如何发送@mark和@city到此过程,并使用c#返回学生的ID.
并且id的类型是整数.

当我使用sqlcommand.ExecuteScalar()时,这是我的错误:
过程或函数getdaytype指定的参数过多.
谢谢,


For example:

create procedure findgoodStudent
@mark int,
@city nvarchar(50)
as
select S_id from students
where @city=S_city and @mark between min and max


How can i send @mark and @city to this procedure and return student''s id with c#.
And type of id is integer.

It''s my error when i use sqlcommand.ExecuteScalar():
Procedure or function getdaytype has too many arguments specified.
thanks,

推荐答案

您将变量添加到SqlCommand的参数集合中.
You add the variables to the parameters collection of the SqlCommand

using(SqlCommand cmd = new SqlCommand("findgoodStudent", connection))
{
   cmd.CommandType = StoreProcedure;
   cmd.Parameters.AddWithValue("@mark", ???);
   cmd.Parameters.AddWithValue("@city", ???);

   object obj = cmd.ExecuteScalar();
}


这篇关于在ido.net和C#中将多个参数传递给sql过程的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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