-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

user3019180
  • 80
  • 1
  • 7
  • 1
    You really should show that code that is 100% correct... – reto Nov 21 '13 at 20:41
  • 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(); – user3019180 Nov 21 '13 at 20:54
  • Please do not post code in the comments. Your chances of getting help are much bigger if you properly edit your original question, including the relevant code and some context. – reto Nov 21 '13 at 20:56
  • This is three unrelated questions in one. – laylarenee Nov 21 '13 at 21:36

1 Answers1

0

The code isn't 100% correct. You can't, and shouldn't, bind to a DataReader. Consider the modified code:

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;
}

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

You just need to install SQL Express. There's a download for it and the installation is straight forward.

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

Do some research on your own, get some code off of a post somewhere, and if you are struggling with that then come back here with some specifics and ask a new question.

Mike Perrenoud
  • 66,820
  • 29
  • 157
  • 232