#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    9
    Rep Power
    0

    Datagridview not working


    Here is my code to display user that is logged in userinfo from mysql DB

    String str = @"server=localhost;database=test101;userid=root;";
    string userinfosql = "SELECT * FROM test101.userinfo where Name = " + username;


    MySqlConnection con = null;
    con = new MySqlConnection(str);
    con.Open();


    {
    DataSet ds = new DataSet();

    MySqlDataAdapter da = new MySqlDataAdapter(userinfosql, con);

    da.Fill(ds, "userinfosql");

    dataGridView1.AutoGenerateColumns = true;
    dataGridView1.DataSource = ds;
    dataGridView1.DataMember = "userinfosql";

    username is a var that contains the users name, it already has a str value, and database has no password


    Thanx so long
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    2
    Rep Power
    0
    same problem with me please help some body.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    26
    Rep Power
    0
    dataGridView1.AutoGenerateColumns = true;
    dataGridView1.DataSource = ds;
    dataGridView1.dataBind(); // you missed it..hope it will work
    dataGridView1.DataMember = "userinfosql";
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2012
    Posts
    9
    Rep Power
    0
    Originally Posted by serviceproz
    dataGridView1.AutoGenerateColumns = true;
    dataGridView1.DataSource = ds;
    dataGridView1.dataBind(); // you missed it..hope it will work
    dataGridView1.DataMember = "userinfosql";


    Added other code to customize the gridview and then your code, and it worked great

    Thanx !!
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2005
    Location
    Bournemouth, Dorset, UK
    Posts
    232
    Rep Power
    10
    I had the same question and found this thread which helped me resolve the problem. I'd missed the DataBind too.

    Thank you!

    www.data-integration-services.co.uk Integration, EDI, Database Admin, Reporting | www.tophatweddings.co.uk

IMN logo majestic logo threadwatch logo seochat tools logo