Подключение к базе данных осуществляется так:
public static MySqlConnection connection = new MySqlConnection();
public static MySqlConnectionStringBuilder builder = new MySqlConnectionStringBuilder();
public static void EstablishConnection()
{
builder.Server = "***.***.*.**";
builder.UserID = "student";
builder.Password = "student";
builder.Database = "recipesbook";
connection = new MySqlConnection(builder.ToString());
}
Далее я пытаюсь записать в datagrid 3 столбца:
string sql = "SELECT name, amount, time from ListOfProducts";
using(MySqlConnection connection = new MySqlConnection(SQLconnect.builder.ToString()))
{
connection.Open();
using(MySqlCommand command = new MySqlCommand(sql, connection))
using (MySqlDataReader dataReader = command.ExecuteReader())
{
if(dataReader.HasRows)
{
while(dataReader.Read())
{
name = dataReader.GetString(0);
amount = dataReader.GetInt32(1);
time = dataReader.GetInt32(2);
}
}
else
{
MessageBox.Show("no rows");
}
}
connection.Close();
Как это вывести в datagrid?