Click here to Skip to main content
12,450,101 members (42,092 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
what error here?

private void fillgrid()
        {
            try
            {
                DataSet ds = new DataSet();
                ds.Clear();
                SqlConnection con = new SqlConnection(@" kkkk");
                SqlCommand comm = new SqlCommand("select * from client", con);
                SqlDataAdapter adapt = new SqlDataAdapter();
                con.Open();
                adapt.SelectCommand = comm;
                adapt.Fill(ds);
                dataGridView1.DataSource = ds;
                dataGridView1.DataMember = "client";
                con.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Posted 31-Jan-13 10:39am
Updated 31-Jan-13 10:43am
v2
Comments
Adam R Harris 31-Jan-13 16:45pm
   
Shouldn't you be telling us what the error is?
jibesh 31-Jan-13 16:50pm
   
what is this ' SqlConnection con = new SqlConnection(@" kkkk");' is that a valid sqlconnection ?
Member 9702410 31-Jan-13 16:58pm
   
the connection is righ i put this "kkk"
Member 9702410 31-Jan-13 16:50pm
   
thanks for your advice!! i only want to know the error?
Adam R Harris 31-Jan-13 16:53pm
   
what is the error message you are getting?
Member 9702410 31-Jan-13 16:59pm
   
no message error ,when clickin on button the gridview doesn't be filled
Adam R Harris 31-Jan-13 17:01pm
   
Comment out this line:
dataGridView1.DataMember = "client";

and try to run your app.
Member 9702410 31-Jan-13 17:08pm
   
i already comment it but also there is no filling
DinoRondelly 31-Jan-13 17:13pm
   
Try what i added as a solution, just copy and paste it and change the connection string, should work.
Adam R Harris 31-Jan-13 17:16pm
   
Dino is right, the code he has posted is what you should be using.
Member 9702410 31-Jan-13 16:51pm
   
yes the connection is righ i put kkk
jibesh 31-Jan-13 16:54pm
   
so what's your problem here? by looking at the code If i say I dont see any error. will it be ok??

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

try this,

try
{
 using (SqlConnection con = new SqlConnection(YOUR CONNECTION STRING))
 {
  con.Open();
 
  // Create new DataAdapter
   using (SqlDataAdapter adapt = new SqlDataAdapter("select * from client", con))
   {
      // Use DataAdapter to fill DataTable
      DataTable ds = new DataTable();
      adapt.Fill(ds);
 
      // fill your grid
      dataGridView1.DataSource = ds;
   }
  }
}
catch(Exception ex)
{
     MessageBox.Show(ex.Message);
}
  Permalink  
v3
Comments
Adam R Harris 31-Jan-13 16:57pm
   
pft, no try catch?!?!?!
what kind of rinky dink operation are you running over there Dino?
DinoRondelly 31-Jan-13 16:59pm
   
Touche .. updated solution

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100