0

我希望能够运行下面的查询并在 div 中逐行返回结果。结果被添加到一个哈希表中,我将把它传递给另一个方法并将其显示在一个 div 中。

数组 arrayOfQueries[0] 中的第一个查询可以返回多行 Que:

  1. 我如何编写它来处理为该数组中的查询返回的多行 --- arrayOfQueries[0]。即我希望能够将多行存储在苛刻的表中,或者我应该使用 stringbuilder 对象。

  2. 如何在 div 中显示哈希表的内容。

    public Hashtable DisplayResultsToUsers(int genJobId)
    {
        Hashtable myHt = new Hashtable();
        try
        {
            string[] arrayOfQueries = new string[4];
            arrayOfQueries[0] = "select generic, customernumber, productcode from u_generic_data where row_status = 2 and generic_job_id =" + genJobId;
            arrayOfQueries[1] = "select count(*) from u_generic_data where row_status = 2 and generic_job_id =" + genJobId;
            arrayOfQueries[2] = "select count(*) from u_generic_data where row_status = 1 and generic_job_id =" + genJobId;
            arrayOfQueries[3] = "select count(*) from u_generic_data where row_status = 0 and generic_job_id =" + genJobId;
    
            string connect = ConfigurationManager.ConnectionStrings["myconnect"].ConnectionString;
    
            using (OdbcConnection resConnect = new OdbcConnection(connect))
            {
                string sqlStmt = string.Empty;
                string queryResult = string.Empty;
                int count = 0;
                OdbcCommand dbCmd = new OdbcCommand();
                dbCmd.Connection = resConnect;
                resConnect.Open();
    
                foreach (string s in arrayOfQueries)
                {
                    dbCmd.CommandText = s;
                    queryResult =  Convert.ToString(dbCmd.ExecuteScalar());
                    count = count + 1;
                    myHt.Add(count, queryResult);
                }
    
                resConnect.Close();
            }
    
        }
        catch (Exception ex)
        {
    
    
        }
    
        return myHt;
    
4

1 回答 1

0

dbCmd.ExecuteScalar()不适用于诸如select generic, customernumber, productcode from u_generic_data where row_status = 2 and generic_job_id =" + genJobId. 您需要做dbCmd.ExecuteReader()或其他一些重载来检索这些列。 ExecuteScalar()查询会很好select count(*)

于 2013-07-17T18:45:11.700 回答