我正在尝试从数据表中的stored procedure
获取所有行,我使用sql profiler
我可以看到参数正常,stored procedure
导致超过2000记录,但我填充的datatable
为空,datagridview
给我null exception
,因为它的数据源是数据表。
public static DataTable GetJobDetails(string p1, string p1, string p3)
{
DataTable dt = new DataTable();
SqlDataAdapter sd;
String strConnString = ConfigurationManager.ConnectionStrings["MyConnectionString"].ConnectionString;
using (SqlConnection con = new SqlConnection(strConnString))
using (SqlCommand cmd = new SqlCommand("usp_GetDetails", con))
{
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add("@p1", SqlDbType.VarChar, 25).Value = p1;
cmd.Parameters.Add("@p2", SqlDbType.VarChar, 100).Value = p2;
cmd.Parameters.Add("@p3", SqlDbType.VarChar, 25).Value = p3;
con.Open();
cmd.Connection = con;
sd = new SqlDataAdapter(cmd);
sd.Fill(dt);
}
return dt;
}
我的datagridview
代码是
DataTable dt = new DataTable();
dt = HondaBL.GetJobDetails(p1, p2, p3);
dataGridView1.DataSource = dt;
这是我简单的Stored Procedure
CREATE PROCEDURE [dbo].[usp_GetDetails]
@p1 varchar(25),
@p2 varchar(100),
@p3 varchar(25)
AS
BEGIN
SELECT somefield1, somefield2, somefield3, somefield4, somefield5
FROM mytable
WHERE p1= @p1
AND p2= @p2
AND p3= @p3
END
我运行了查询,我从sql profiler
开始,它显示的结果超过了2000行。