Click here to Skip to main content
15,879,096 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
what error here?

C#
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
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?

1 solution

try this,

C#
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);
}
 
Share this answer
 
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)



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