Welcome to WebmasterWorld Guest from 54.196.2.131

Forum Moderators: open

MYSQL table to C# list

     
4:36 pm on Nov 4, 2017 (gmt 0)

Junior Member

5+ Year Member

joined:Oct 19, 2011
posts: 174
votes: 1


I'm migrating my program from using a local SQLIte database to an online MYSQL database in C#. To do so, I need to use a list to grab the information from a table, but I'm not sure how to do it for MYSQL.

Here is one of the functions I used for the SQLite version:
public List<CarInfo> MakeCarInfoList()
{
_connection = new SqliteConnection(_sqlDBLocation);
_command = _connection.CreateCommand();
_connection.Open();
_sqlString = "SELECT * FROM " + SQL_TABLE_CAR;
_command.CommandText = _sqlString;
_command.ExecuteNonQuery();
_reader = _command.ExecuteReader();

while (_reader.Read())
{
CarInfoList.Add(new CarInfo(_reader.GetString(0),
_reader.GetString(1),
_reader.GetString(2),
_reader.GetString(3)));

}


_reader.Close();
_connection.Close();

return CarInfoList;
}



Could someone walk me through? Thanks!