我正在使用MySql中的MySql.Data dll并尝试执行查询以将数据从MySQL表传输到MSSQL表。我正在运行以下代码:
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();
当我在同一个数据库的MySQL查询浏览器中直接运行此查询时,它返回115条记录。但是在程序中,使用上面的代码。它返回106行。没什么不同的,我很沮丧。有线索吗?
更新
这就是我测试返回记录的数量:
这是Mysql查询浏览器中的相同查询
答案 0 :(得分:0)
请尝试一些事情链接这个。
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;
}
}