存储过程没有参数时该怎么调用
比如:ALTER PROCEDURE get_user
AS
select name1 from T_student
RETURN
这个存储过程,用C#写调用代码,怎么写?
------解决方案--------------------不传参就是了
Sqlconnecticon=new Sqlconnection("");
Sqlcommand cmd=new Sqlcommand("get_user",con);
cmd.commandType=commandType.storedprocedure;
con.open();
SqlDataReader sdr = cmd.ExecuteReader();
con.close();
------解决方案--------------------C# code
public static int ExecuteNonQuery(string cmdtext, CommandType ct)
{
int value;
try
{
cmd = new SqlCommand(cmdtext, GetConn());
cmd.CommandType = ct;
value = cmd.ExecuteNonQuery() > 0 ? 1 : 0;
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (cn.State == ConnectionState.Open)
{
cn.Close();
}
}
return value;
}