我有一个问题,在WPF使用DataGrid,我使用SQLDataReader,当我填充记录从数据表到数据网格没有记录,但它hasRows我的代码是这样的。
try
{
string commandText = "dbo.sp_select_survey";
SqlConnection conn = new SqlConnection("Data Source=IT-PC1;Initial Catalog=gcserp;User ID=test;Password=test;Initial Catalog=gcserp;Integrated Security=True");
SqlCommand cmd = new SqlCommand(commandText, conn);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
cmd.CommandTimeout = 600;
conn.Open();
SqlDataReader objRDR = cmd.ExecuteReader((CommandBehavior.CloseConnection));
DataTable dt = new DataTable();
dt.Load(objRDR);
dataGrid1.ItemsSource=dt.DefaultView;
}
catch
{
}发布于 2012-07-24 16:30:27
我不确定你的aspx页面是什么样子的,你的datagrid中有什么设置,但我会首先测试datagrid,不定义任何边界列或自定义模板列,并确保autogeneratecolumns设置为true。只是一些基本的东西,比如看看你的数据是否会绑定到网格:
<asp:datagrid id="dataGrid1" runat="server" />还要确保不返回任何空值,并在查询中包含ISNULL(field,'')。
最后,在.net框架4中,您应该使用gridview而不是datagrid...not来确定这是否是一个拼写错误。
发布于 2012-07-26 17:14:53
我觉得你应该这样说:
Integrated Security = trueOR User ID = "" and Password = "" '
https://stackoverflow.com/questions/11626686
复制相似问题