Filling a DataTable in C# using MySQL

前端 未结 5 1828
陌清茗
陌清茗 2021-01-07 14:33

I\'m attempting to fill a DataTable with results pulled from a MySQL database, however the DataTable, although it is initialised, doesn\'t populate. I wanted to use this Dat

5条回答
  •  终归单人心
    2021-01-07 14:52

    Check your connection string and instead of using

    MySqlCommand cmd = new MySqlCommand(query, connection);
    MySqlDataAdapter returnVal = new MySqlDataAdapter(query,connection);
    DataTable dt = new DataTable("CharacterInfo");
    returnVal.Fill(dt);
    this.CloseConnection();
    return dt;
    

    you can use this one

    MySqlCommand cmd = new MySqlCommand(query, connection);
    DataTable dt = new DataTable();
    dt.load(cmd.ExecuteReader());
    return dt;
    

提交回复
热议问题