Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ssis/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/qt/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 从AS400存储过程返回结果集_C#_Ssis - Fatal编程技术网

C# 从AS400存储过程返回结果集

C# 从AS400存储过程返回结果集,c#,ssis,C#,Ssis,我正在努力使用C#控制台应用程序从AS400数据库返回结果集。。。我可以连接到数据库,并且我已经通过AS400日志验证了连接,但是我似乎遇到了以下错误: System.InvalidCastException未处理 Message=提供程序当前不支持返回的数据类型。 Source=IBM.Data.DB2.iSeries 堆栈跟踪: 位于IBM.Data.DB2.iSeries.iDB2DbTypeUtility.MapSQLTypeToDCPCType(DcSqlTypes-sqlType,I

我正在努力使用C#控制台应用程序从AS400数据库返回结果集。。。我可以连接到数据库,并且我已经通过AS400日志验证了连接,但是我似乎遇到了以下错误:

System.InvalidCastException未处理 Message=提供程序当前不支持返回的数据类型。 Source=IBM.Data.DB2.iSeries 堆栈跟踪: 位于IBM.Data.DB2.iSeries.iDB2DbTypeUtility.MapSQLTypeToDCPCType(DcSqlTypes-sqlType,Int32-colccsid,UInt32-length) 位于IBM.Data.DB2.iSeries.iDB2Command.setRowOfParameterData(MpDcData[]和dcDataRow) 在IBM.Data.DB2.iSeries.iDB2Command.execute()中 在IBM.Data.DB2.iSeries.iDB2Command.ExecuteNonQuery()上 在C:\Users\harlim\documents\visual studio 2010\Projects\GeacFutureDelivery\GeacFutureDelivery\Program.cs中的GeacFutureDelivery.Program.Main(字符串[]args)处:第40行 位于System.AppDomain.\u nExecuteAssembly(RuntimeAssembly程序集,字符串[]args) 位于System.AppDomain.ExecuteAssembly(字符串汇编文件、证据汇编安全性、字符串[]args) 在Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()上 位于System.Threading.ThreadHelper.ThreadStart\u上下文(对象状态) 在System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态,布尔ignoreSyncCtx) 在System.Threading.ExecutionContext.Run(ExecutionContext ExecutionContext,ContextCallback回调,对象状态) 位于System.Threading.ThreadHelper.ThreadStart()处 内部异常:

我的消息来源是:

var connectionString = "<Connection String>";
        int startDate = 1120530;
        int endDate = 1120602;

        try
        {
            using (var connection = new iDB2Connection(connectionString))
            {
                connection.Open();

                iDB2Transaction trans = connection.BeginTransaction();

                iDB2Command command = connection.CreateCommand();


                string query = "DRLOBJ01.GETORDPCD";
                command.Transaction = trans;
                command.CommandType = CommandType.StoredProcedure; 
                command.CommandText = query;
                command.CommandTimeout = 0;

                command.Parameters.Add("DTSTR", iDB2DbType.iDB2Integer).Value = startDate;
                command.Parameters.Add("DTEND", iDB2DbType.iDB2Integer).Value = endDate;

                command.Prepare();


                using (iDB2DataReader reader = command.ExecuteReader())
                 {
                    int iCUSO51 = reader.GetOrdinal("CUSO51");
                    int iORDN51 = reader.GetOrdinal("ORDN51");
                    int iDTDR51 = reader.GetOrdinal("DTDR51");
                    int iOPST45 = reader.GetOrdinal("OPST45");

                    while (reader.Read())
                    {
                        if (!string.IsNullOrEmpty(reader.GetString(iCUSO51)))
                        {
                            Console.WriteLine((string)reader[iCUSO51]);
                            Console.WriteLine((string)reader[iORDN51]);
                            Console.WriteLine((string)reader[iDTDR51]);
                            Console.WriteLine((string)reader[iOPST45]);
                        }
                    }
                }
            }
        }
        catch (iDB2CommErrorException ex)
        {
            Console.WriteLine(ex.Message);
        }
    }
var connectionString=“”;
int startDate=1120530;
int endDate=1120602;
尝试
{
使用(var连接=新IDB2连接(connectionString))
{
connection.Open();
iDB2Transaction trans=connection.BeginTransaction();
iDB2Command=connection.CreateCommand();
string query=“DRLOBJ01.GETORDPCD”;
command.Transaction=trans;
command.CommandType=CommandType.storedProcess;
command.CommandText=查询;
command.CommandTimeout=0;
Add(“DTSTR”,iDB2DbType.iDB2Integer).Value=startDate;
Add(“DTEND”,iDB2DbType.iDB2Integer).Value=endDate;
command.Prepare();
使用(iDB2DataReader=command.ExecuteReader())
{
int iCUSO51=reader.GetOrdinal(“CUSO51”);
int iORDN51=reader.GetOrdinal(“ORDN51”);
int iDTDR51=reader.GetOrdinal(“DTDR51”);
int iOPST45=reader.GetOrdinal(“OPST45”);
while(reader.Read())
{
如果(!string.IsNullOrEmpty(reader.GetString(iCUSO51)))
{
Console.WriteLine((字符串)读取器[iCUSO51]);
Console.WriteLine((字符串)读取器[iORDN51]);
WriteLine((字符串)读取器[iDTDR51]);
Console.WriteLine((字符串)读取器[iOPST45]);
}
}
}
}
}
捕获(iDB2CommErrorException ex)
{
控制台写入线(例如消息);
}
}

有什么想法吗?

如果您的值是字节[],我想您在使用CCSID65535时遇到了一些问题

如果是这样,下面是一个代码来解决它:-)

专用数据表parseCCSID65535(数据表p_dt)
{
DataTable dt=新的DataTable();
//构建一个新的数据表
对于(int i=0;i
4列的预期数据类型是什么?如果删除while循环中的整个If块,它是否成功运行?这将有助于缩小查询位或从datareader中提取数据的范围。此外,如果您有机会,您是否可以查看您的答案和标记,或者提供一些反馈?数据类型为CUSO51 Char(15)、ORDN51 Char(7)、DTDR51 DEC(7,0)和OPST45 Char(12)。现在,我将结束我的开放式问题。如果不尝试访问datareader的值,会发生什么?我假设代码可以在resultset中进行迭代,但是数据的访问会很麻烦。
 private DataTable parseCCSID65535(DataTable p_dt)
 {
     DataTable dt = new DataTable();

     // Build a new DataTable
     for (int i = 0; i < p_dt.Columns.Count; i++)
     {
         dt.Columns.Add(p_dt.Columns[i].Caption);
     }

     //loop through the rows
     for (int r = 0; r < p_dt.Rows.Count; r++)
     {
         //create a new row
         string[] row = new string[p_dt.Columns.Count];

         //loop through all columns
         for (int c = 0; c < p_dt.Columns.Count; c++)
         {
             if (p_dt.Rows[r][c].GetType() == typeof(System.Byte[]))
             {
                 // if this value is CCSID65535, change it ;-)
                 iDB2CharBitData cbd = new iDB2CharBitData((Byte[])p_dt.Rows[r][c]);
                 row[c] = cbd.ToString(65535);
             }
             else
             {
                 // else: go on.
                 row[c] = p_dt.Rows[r][c].ToString();
             }
         }
         // passing to the new DataTable.
         dt.Rows.Add(row);
     }
     return dt;
 }