What I would like to do is to be able to read record by record as the table is advanced, just to be able to extract the record that I want whenever I want, add a Mysql reader for that, but I do not know why motive marks me the following error:
Connection must be valid and open.
Connection Code
server = "localhost";
database = "presupuesto";
uid = "root";
password = "";
string connectionString;
connectionString = "SERVER=" + server + ";" + "DATABASE=" +
database + ";" + "UID=" + uid + ";" + "PASSWORD=" + password + ";";
connection = new MySqlConnection(connectionString);
string Query = "select Id_Compra,Articulo,Categoria,Obligatorio,Costo,Adquirir from compra";
MySqlConnection MyConn2 = new MySqlConnection(connectionString);
MySqlCommand MyCommand2 = new MySqlCommand(Query, MyConn2);
//For offline connection we weill use MySqlDataAdapter class.
MySqlDataAdapter MyAdapter = new MySqlDataAdapter();
MyAdapter.SelectCommand = MyCommand2;
DataTable dTable = new DataTable();
Reading Code.
if (this.connection.State == ConnectionState.Closed)
{
this.connection.Open();
MySqlDataReader rdr = MyCommand2.ExecuteReader();
while (rdr.Read())
{
for (int x = 0; x < 10; x++)
{
MessageBox.Show(Convert.ToString(x), "Inidce", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
}
}
}