I'm using the MySql.Data dll from MySql and trying to execute a query to transfer data from a MySQL table to an MSSQL table. I am running the following code:
MySqlCommand catCmd = new MySqlCommand();
catCmd.CommandType = System.Data.CommandType.Text;
catCmd.Connection = connection;
//Add categories to static class
catCmd.CommandText = "SELECT c.categories_id, categories_image, parent_id, categories_status, categories_name, categories_description FROM categories c JOIN categories_description d ON c.categories_id = d.categories_id ORDER BY categories_status";
MySqlDataReader catReader = catCmd.ExecuteReader();
while (catReader.Read())
{
try
{
tables.categories.Add(new category(0, catReader.GetInt32(0), catReader.GetString(1), catReader.GetInt32(2), catReader.GetInt32(3), catReader.GetString(4), catReader.GetString(5)));
}
catch
{
tables.categories.Add(new category(0, catReader.GetInt32(0), "", catReader.GetInt32(2), catReader.GetInt32(3), catReader.GetString(4), catReader.GetString(5)));
}
}
reader.Close();
When I ru开发者_如何学JAVAn this query directly in MySQL query browser on the same DB it returns 115 records. But within the program, with the code above. It returns 106 rows. Theres nothing diffrent and i'm very frustrated. Any clues?
UPDATE
This is how i'm testing for the number of returned records:
Here is the same query in Mysql Query Browser
Please Try Some thing Link this.
public DataTable DataReader(string query)
{
DataTable mysqlDataTable = new DataTable();
try
{
ConnectToMysql();// Add Mysql Connection Here.
MySqlDataAdapter readerAdapter = new MySqlDataAdapter(query, MysqlDBConnection);//MySqlConnection MysqlDBConnection;
readerAdapter.Fill(mysqlDataTable);
readerAdapter.Dispose();
MysqlDBConnection.Close();
MysqlDBConnection.Dispose();
return mysqlDataTable;
}
catch
{
throw;
}
}
精彩评论