簡體   English   中英

在聲明為C#之前不能使用“ Int32”

[英]Cannot use 'Int32' before it is declared C#

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;


public class StockMainDL
{
    string conString = "Data Source=KamranAhmed\\SQLEXPRESS;Initial Catalog=City_Car;Integrated Security=True";
    SqlConnection con;
    SqlCommand com;
    SqlDataAdapter da;
    DataSet ds;

    public StockMainDL()
    {
        con = new SqlConnection(conString);
        con.Open();
    }


    public List<StockMain> GetChartData(string mode)
    {
        List<StockMain> stockMain = new List<StockMain>();

        string query = "SELECT * FROM StockMain";
        com = new SqlCommand(query);
        da = new SqlDataAdapter(query, con);
        da.Fill(ds);


        foreach (DataRow item in ds.Tables[0].Rows)
        {

            stockMain.Add(new StockMain(Int32.Parse(item["Stid"]), Int32.Parse(item["Vrno"]), Int32.Parse(item["Vrnoa"]), Convert.ToDateTime(item["Vrdate"]), item["Party_id"].ToString(), item["Bilty_No"].ToString(), Convert.ToDateTime(item["Bilty_Date"]), item["Received_By"].ToString(), item["Transporter_id"].ToString(), item["Remarks"].ToString(), Int32.Parse(item["Year_Srno"]), item["EType"].ToString(), Int32.Parse(item["NAmount"]), Int32.Parse(item["UId"]), Int32.Parse(item["VrNo"]), Int32.Parse(item["OrderVrNo"]), Int32.Parse(item["Freight"]), item["Party_Id_Co"].ToString(), Int32.Parse(item["SaleBillNo"]), float Discp, float Discount, Int32.Parse(item["Currency_Id"]), float Expense, Int32.Parse(item["Company_Id"]), item["Vehicle_Id"].ToString(), Convert.ToBoolean(Item["IsEditted"]), Convert.ToBoolean(Item["IsNew"]), Convert.ToBoolean(Item["IsDeleted"])));

        }

        return stockMain;
    }
}

上面是我用來首先從數據庫中獲取數據集並將此數據集轉換為列表,然后返回此列表的代碼。 我遇到的問題是,在foreach循環中,它給出此錯誤“在聲明前不能使用'Int32'”,我嘗試使用Convert.ToInt32(),它對“ Convert”給出相同的錯誤。

有人可以告訴我我在做什么錯嗎? 謝謝

您使用的Item ,而不是item內部的for循環幾個參數。 那就是拋出這個錯誤。 請記住,使用的變量區分大小寫

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM