Click here to Skip to main content
16,019,740 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to get Sqlserver 2005 data in gridview and I am trying but not issue and when I run the page nothing displayed. There is the code source below.
C#
string myConnection = "Data Source=LOCALHOST;Initial Catalog=WFL;User      ID=lapmee;pwd=nininahazwebeni";
                string sql = "select * from Affectation";
                SqlCommand command = new SqlCommand(sql, myConnection);
                SqlDataAdapter adapter = new SqlDataAdapter(command);
                DataSet data = new DataSet();
                adapter.Fill(data);
                GridView1.DataSource = data;
                GridView1.DataBind();

I am using MS Visual Studio 2008 as editor.

So anyone has knowledge can help me because is urgent.
Posted
Updated 9-Feb-15 23:40pm
v2
Comments
ZurdoDev 10-Feb-15 7:51am    
Does this code run? Put a breakpoint on it.

Do you have columns defined in your grid?

1 solution

C#
string myConnection = "Data Source=LOCALHOST;Initial Catalog=WFL;User      ID=lapmee;pwd=nininahazwebeni";
                string sql = "select * from Affectation";
                SqlCommand command = new SqlCommand(sql, myConnection);
                SqlDataAdapter adapter = new SqlDataAdapter(command);
                myConnection.open();
                DataSet data = new DataSet();
                adapter.Fill(data);
                myConnection.close();
                GridView1.DataSource = data.Table[0];
                GridView1.DataBind();
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900