-3

I have 3 questions need help ,please

1- in windows application datagridview doesn't show data ,although the code is correct 100% and I tried the code in gridview in web app and it worked properly .

and when I tried to bind data to datagridview wizard it worked .

I tried a very simple query to ensure the datagridview is doesn't work

 SqlCommand cmd = new SqlCommand("select dep from department", con); 
con.Open();
 SqlDataReader read = cmd.ExecuteReader(); 
dataGridView1.DataSource = read;
 con.Close(); 

2- how can I run a deployed windows app connected to sql server database in a pc without need to setup sql server management studio

3- how to make windows app trial and work after entering specific serial no

thanks in advance

4

1 回答 1

0

代码不是 100% 正确的。您不能也不应该绑定到DataReader. 考虑修改后的代码:

using (SqlConnection con = new SqlConnection(cString))
using (SqlCommand cmd = new SqlCommand("select dep from department", con))
{
    var dt = new DataTable();
    dt.Load(cmd.ExecuteReader());

    dataGridView1.DataSource = dt;
}

如何在 PC 中运行连接到 sql server 数据库的已部署 Windows 应用程序,而无需设置 sql server management studio

您只需要安装 SQL Express。有一个下载,安装很简单。

输入特定序列号后如何使Windows应用程序试用和工作

自己做一些研究,从某处的帖子中获取一些代码,如果你正在努力解决这个问题,那么回到这里并提出一些细节并提出一个新问题。

于 2013-11-22T15:29:34.917 回答