'System.Convert'不包含'Toint32'的定义 [英] 'System.Convert' does not contain a definition for 'Toint32'
问题描述
使用System;
使用System.Configuration;
使用System.Data;
使用System.Linq;
使用System.Collections;
使用System .Collections.Generic;
使用System.Web.UI.WebControls;
使用System .Web.UI.WebControls.WebParts;
使用System.Xml.Linq;
使用System.IO;
使用System.Data。 OleDb;
使用System.ComponentModel;
public partial class _Default:System.Web.UI.Page
{
class Point {double X,Y; }
DataTable dt = new DataTable();
protected void Page_Load(object sender,EventArgs e)
{
}
protected void btnSubmit_Click(object sender,EventArgs e)
{
string connectionString =;
if(FileUpload1.HasFile)
{
string fileName = Path.GetFileName(FileUpload1。 PostedFile.FileName);
string fileExtension = Path.GetExtension(FileUpload1.PostedFile.FileName);
string fileLocation = Server.MapPath(〜/ App_Data /+ fileName );
FileUpload1.SaveAs(fileLocation);
if(fileExtension ==。xls)
{
connectionString =Provider = Microsoft.Jet.OLEDB.4.0; Data Source =+ fileLocation +; Extended Properties = \Excel 8.0; HDR = Yes; IMEX = 2 \;
}
else if(fileExtension ==。xlsx)
{
connectionString =Provider = Microsoft.ACE.OLEDB.12.0; Data Source =+ fileLocation +;扩展属性= \Excel 12.0; HDR =是; IMEX = 2 \;
}
OleDbConnection con = new OleDbConnection(connectionString) ;
OleDbCommand cmd = new OleDbCommand();
ArrayList List = new ArrayList();
cmd.CommandType = System.Data.CommandType .Text;
cmd.Connection = con;
OleDbDataAdapter dAdapter = new OleDbDataAdapter(cmd);
DataTable dtExcelRecords = new DataTable();
con.Open();
DataTable dtExcelSheetName = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables,null);
string getExcelSheetName = dtExcelSheetName.Rows [0] [Table_Name]。ToString();
cmd.CommandText =SELECT * FROM [+ getExcelSheetName +];
dAdapter.SelectCommand = cmd;
dAdapter.Fill(dtExcelRecords);
if(Session [dtInSession]!= null)
{
dt =(DataTable)Session [dtInSession];
}
for(int i = 0;我< dtExcelRecords.Rows.Count; i ++)
{
//如果你想得到字符串
DataRow thisRow =(DataRow)dtExcelRecords.Rows [i];
int X = Convert.Toint32(thisRow [X]);
int Y = Convert.Toint32(thisRow [Y]);
// double Length = Convert.ToDouble(Y);
// double X1 = Convert.ToDouble(X);
// double Y1 =转换。 ToDouble(Y);
DataRow dr = dt.NewRow();
polygonArea(X,Y);
} < br $>
}
}
//计算
private Double polygonArea(int [ ] X,int [] Y)
{
双面积= 0.0;
int j = X.Length - 1;
for(int i = 0; i< X.Length; i ++)
{
area = area +(X [j] + X [我] *(Y [j] - Y [i]));
j = i;
}
area = area / 2;
if(area< 0)
area = area * -1;
返回区域;
}
}
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Collections;
using System .Collections.Generic ;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
using System.Data.OleDb;
using System.ComponentModel;
public partial class _Default : System.Web.UI.Page
{
class Point { double X, Y; }
DataTable dt = new DataTable();
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnSubmit_Click(object sender, EventArgs e)
{
string connectionString = "";
if (FileUpload1.HasFile)
{
string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
string fileExtension = Path.GetExtension(FileUpload1.PostedFile.FileName);
string fileLocation = Server.MapPath("~/App_Data/" + fileName);
FileUpload1.SaveAs(fileLocation);
if (fileExtension == ".xls")
{
connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";
}
else if (fileExtension == ".xlsx")
{
connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";
}
OleDbConnection con = new OleDbConnection(connectionString);
OleDbCommand cmd = new OleDbCommand();
ArrayList List = new ArrayList();
cmd.CommandType = System.Data.CommandType.Text;
cmd.Connection = con;
OleDbDataAdapter dAdapter = new OleDbDataAdapter(cmd);
DataTable dtExcelRecords = new DataTable();
con.Open();
DataTable dtExcelSheetName = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
string getExcelSheetName = dtExcelSheetName.Rows[0]["Table_Name"].ToString();
cmd.CommandText = "SELECT * FROM [" + getExcelSheetName + "]";
dAdapter.SelectCommand = cmd;
dAdapter.Fill(dtExcelRecords);
if (Session["dtInSession"] != null)
{
dt = (DataTable)Session["dtInSession"];
}
for (int i = 0; i < dtExcelRecords.Rows.Count; i++)
{
//if you want to get the string
DataRow thisRow = (DataRow)dtExcelRecords.Rows[i];
int X = Convert.Toint32(thisRow["X"]);
int Y = Convert.Toint32 (thisRow["Y"]);
//double Length = Convert.ToDouble(Y);
//double X1 = Convert.ToDouble(X);
//double Y1 = Convert.ToDouble(Y);
DataRow dr = dt.NewRow();
polygonArea(X, Y);
}
}
}
//calculation
private Double polygonArea(int[] X, int[] Y)
{
Double area = 0.0;
int j = X.Length - 1;
for (int i = 0; i < X.Length; i++)
{
area = area + (X[j] + X[i] * (Y[j] - Y[i]));
j = i;
}
area = area / 2;
if (area < 0)
area = area * -1;
return area;
}
}
推荐答案
这是因为C#区分大小写。尝试更改:
That is because C# is case sensitive. Try changing:
int X = Convert.Toint32(thisRow["X"]);
int Y = Convert.Toint32 (thisRow["Y"]);
收件人:
To:
int X = Convert.ToInt32(thisRow["X"]);
int Y = Convert.ToInt32 (thisRow["Y"]);
您可以使用以下转换方法
Int32 n = Int32.Parse();
int n = Convert.ToInt32();
Int32.TryParse();
int n = int.Parse();
You can use following conversion method
Int32 n = Int32.Parse();
int n = Convert.ToInt32();
Int32.TryParse();
int n = int.Parse();
这篇关于'System.Convert'不包含'Toint32'的定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!