提出了Sql Exception。 [英] Sql Exception raised.
本文介绍了提出了Sql Exception。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
代码
code in dataaccesslayer
public DataSet FindRecord(int RollNumber)
{
using (SqlConnection con = new SqlConnection(cs))
{
//string cmd = "Select * from tblstudent where RollNumber=@RollNumber";
SqlCommand cmd = new SqlCommand("Select * from tblstudent where RollNumber=@RollNumber", con);
cmd.Parameters.AddWithValue("@RollNumber", RollNumber);
SqlDataAdapter da = new SqlDataAdapter("spfindtblstudent", con);
cmd.CommandType = CommandType.StoredProcedure;
con.Open();
DataSet ds = new DataSet();
da.Fill(ds);
con.Close();
return ds;
}
我的存储过程是
My stored procedure is
alter procedure spfindtblstudent
@RollNumber int
as
Begin
Select * from tblstudent Where RollNumber=@RollNumber
END
推荐答案
看起来你在发送直接SQL命令和调用存储过程之间混合。尝试决定你要使用哪一个。
Looks like you are mixing between sending direct SQL commands and calling a stored procedure. Try to decide which one you want to use.
public DataSet FindRecord(int RollNumber)
{
using (SqlConnection con = new SqlConnection(cs))
{
//string cmd = "Select * from tblstudent where RollNumber=@RollNumber";
SqlCommand cmd = new SqlCommand();
cmd.Connection = con;
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "spfindtblstudent";
cmd.Parameters.AddWithValue("@RollNumber", RollNumber);
con.Open();
SqlDataAdapter da = new SqlDataAdapter()
da.SelectCommand = cmd;
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
}
由于您没有指定确切的异常消息,我只能猜测这个是问题。
As you don't specify your exact exception message, I can only guess that this is the problem.
这篇关于提出了Sql Exception。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文