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”给出了相同的错误。
谁能告诉我我做错了什么?谢谢