我在执行数据表时是否做错了什么?这是我第一次尝试通过Visual Studio发送查询(只知道如何从mySQL查询),所以我可能还很遥远。
没有编译错误,但是运行它不会产生任何输出。
using System.Data;
using System.Configuration;
using MySql.Data.MySqlClient;
using System.Collections.Generic;
public class sp_criteria
{
public DataTable dataTable(string procedureName, Dictionary<string, object> parameterList)
{
DataTable outputDataTable;
using (MySqlConnection MySqlConnection = new MySqlConnection("Server=localhost;" +
"Port = 1234" +
"Database=heatco;" +
"Uid=root;" +
"Pwd=123456;"))
MySqlConnection.Open();
{
using (MySqlCommand sqlCommand = new MySqlCommand(procedureName, MySqlConnection))
{
sqlCommand.CommandType = CommandType.StoredProcedure;
if (parameterList != null)
{
foreach (string key in parameterList.Keys)
{
string parameterName = key;
object parameterValue = parameterList[key];
sqlCommand.Parameters.Add(new MySqlParameter("intMaxCFM", 10000));
sqlCommand.Parameters.Add(new MySqlParameter("intMinCFM", 2223));
sqlCommand.Parameters.Add(new MySqlParameter("intMinMbh", 300));
sqlCommand.Parameters.Add(new MySqlParameter("dblDimA", 20000));
sqlCommand.Parameters.Add(new MySqlParameter("dblDimB", 20000));
sqlCommand.Parameters.Add(new MySqlParameter("dblDimC", 20000));
sqlCommand.Parameters.Add(new MySqlParameter("dblDimD", 20000));
MySqlCommand cm = new MySqlCommand("CALL sp_criteria()", MySqlConnection);
}
}
MySqlDataAdapter sqlDataAdapter = new MySqlDataAdapter(sqlCommand);
DataSet outputDataSet = new DataSet();
sqlDataAdapter.Fill(outputDataSet, "compatibleset");
outputDataTable = outputDataSet.Tables["compatibleset"];
}
}
return outputDataTable;
}
}
最佳答案
您在声明局部变量cm
,但从未使用过:
MySqlCommand cm = new MySqlCommand("CALL sp_criteria()", MySqlConnection);
而是在创建存储过程名称时在
sqlCommand
上设置它(不需要CALL
)。 (此外,您问题中MySqlConnection
周围的花括号看起来是错误的,因此我已在此处将其修复。)using (MySqlConnection MySqlConnection = new MySqlConnection(connectionString))
using (MySqlCommand sqlCommand = new MySqlCommand(procedureName, MySqlConnection))
{
MySqlConnection.Open();
sqlCommand.CommandType = CommandType.StoredProcedure;
// ADD THIS
sqlCommand.CommandText = "sp_criteria";
关于c# - 在Visual Studio C#中从MySQL执行存储过程时无输出,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/48710646/