0

I'm trying to retrieve data from a database to a datagridview but i'm getting an exception,

The ConnectionString property has not been initialized.

using (conn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=""C:\Users\BOB\Documents\Visual Studio 2012\Projects\Login\Login\Student_Marks.mdf"";Integrated Security=True"));
{
     using (adap = new SqlDataAdapter("select * from tbl_Students_Marks", conn))
     {
          DataSet das = new DataSet();
          adap.Fill(das);
          dataGridView1.DataSource = ds.Tables[0];
     }
}
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
M_Magz
  • 43
  • 1
  • 7

1 Answers1

1

i see your code and found that you placed ";" and the end of your first using statement where you initiating conn

using (conn = new SqlConnection(@"Data Source=(LocalDB)\v11.0;AttachDbFilename=""C:\Users\BOB\Documents\Visual Studio 2012\Projects\Login\Login\Student_Marks.mdf"";Integrated Security=True"))//; this was the issue
{
     using (adap = new SqlDataAdapter("select * from tbl_Students_Marks", conn))
     {
          DataSet das = new DataSet();
          adap.Fill(das);
          dataGridView1.DataSource = das.Tables[0];//this must be das not ds
     }
}
Amit Tiwari
  • 368
  • 1
  • 4