Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# WinForm
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
Edited 31-Jan-13 10:43am
v2
Comments
Adam R Harris at 31-Jan-13 16:45pm
   
Shouldn't you be telling us what the error is?
jibesh at 31-Jan-13 16:50pm
   
what is this ' SqlConnection con = new SqlConnection(@" kkkk");' is that a valid sqlconnection ?
Member 9702410 at 31-Jan-13 16:58pm
   
the connection is righ i put this "kkk"
Member 9702410 at 31-Jan-13 16:50pm
   
thanks for your advice!! i only want to know the error?
Adam R Harris at 31-Jan-13 16:53pm
   
what is the error message you are getting?
Member 9702410 at 31-Jan-13 16:59pm
   
no message error ,when clickin on button the gridview doesn't be filled
Adam R Harris at 31-Jan-13 17:01pm
   
Comment out this line:
dataGridView1.DataMember = "client";
 
and try to run your app.
Member 9702410 at 31-Jan-13 17:08pm
   
i already comment it but also there is no filling
DinoRondelly at 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 at 31-Jan-13 17:16pm
   
Dino is right, the code he has posted is what you should be using.
Member 9702410 at 31-Jan-13 16:51pm
   
yes the connection is righ i put kkk
jibesh at 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 at 31-Jan-13 16:57pm
   
pft, no try catch?!?!?!
what kind of rinky dink operation are you running over there Dino?
DinoRondelly at 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
0 Dnyaneshwar@Pune 604
1 OriginalGriff 394
2 thatraja 370
3 Sergey Alexandrovich Kryukov 329
4 CPallini 179
0 OriginalGriff 697
1 Dnyaneshwar@Pune 604
2 Kornfeld Eliyahu Peter 495
3 thatraja 370
4 Sergey Alexandrovich Kryukov 344


Advertise | Privacy | Mobile
Web01 | 2.8.140827.1 | Last Updated 31 Jan 2013
Copyright © CodeProject, 1999-2014
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