我有一组存储过程用于填充ASP.Net CheckBoxList。当从代码运行此过程为{CALL ProcedureName(params); }类型设置为存储过程,我似乎只得到了部分结果(即实际结果中的许多列都丢失了)。MySQL ODBC存储过程结果缺少列
如果我从查询中复制CommandText(使用断点来获取确切的文本发送),并直接在Navicat(或任何其他MySQL GUI)中运行它,我会得到所有预期的列。
这是不正常的代码:
using (OdbcCommand command = OdbcConnection.CreateCommand())
{
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "{ " + string.Format(StoredProcedureCall, foundationId, fpids, "", "", "NULL", "2001/01/02", "2001/01/01", "*") +
" }";
using (OdbcDataReader reader = command.ExecuteReader())
{
for (int i = 0; i < reader.FieldCount; i++)
{
columns.Add(reader.GetName(i));
}
}
}
如果我的代码更改为以下但它开始工作(仅使用添加其他):
using (OdbcConnection)
using (OdbcCommand command = OdbcConnection.CreateCommand())
{
command.CommandType = CommandType.StoredProcedure;
command.CommandText = "{ " + string.Format(StoredProcedureCall, foundationId, fpids, "", "", "NULL", "2001/01/02", "2001/01/01", "*") +
" }";
using (OdbcDataReader reader = command.ExecuteReader())
{
for (int i = 0; i < reader.FieldCount; i++)
{
columns.Add(reader.GetName(i));
}
}
}
是什么去这里?
仅供参考这里是OdbcConnection属性:
public static OdbcConnection OdbcConnection
{
get
{
// If we have no connection or our connection isn't open
if (null == odbcConnection || ConnectionState.Open != odbcConnection.State)
{
odbcConnection = new OdbcConnection(BaseAccess.DBConnectionString);
odbcConnection.Open();
}
return odbcConnection;
}
}
如果您的应用程序使用与Navicat相同的登录凭据? – 2009-10-15 19:59:01
是的,他们使用相同的用户/密码运行 – mikeschuld 2009-10-15 20:03:33
您是如何发现列丢失的?你用什么来存储SP发送的数据? – manji 2009-10-15 20:31:46