Lo que me gustaria hacer es poder leer registro por registro conforme vaya avanzado el llenado de mi tabla, solamente para poder extraer el registro que yo quiera en el momento que quiera, agregue para eso un reader de Mysql, pero no se porque motivo me marca el siguient error:
Connection must be valid and open.
Codigo de Conexion
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();
Codigo de Lectura.
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);
}
}
}
MyCommand2
?