简体   繁体   中英

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;
    }
}

Above is the code that I'm using to first get the dataset from the database and the transform this dataset to a List and then return this list. The problem I'm having is, inside the foreach loop it gives this error "Cannot use 'Int32' before it is declared", I tried to use Convert.ToInt32() it gives the same error for "Convert".

Can anybody please tell me what I'm doing wrong? Thanks

you are using Item instead of item inside that FOR loop for few parameters. That is throwing you this error. Remember the variables used are case-sensitive

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM