'System.Data.DataRow'不包含'Item'的定义,并且没有扩展方法'Item'可以找到接受类型'System.Data.DataRow'的第一个参数(你是否错过了使用... [英] 'System.Data.DataRow' does not contain a definition for 'Item' and no extension method 'Item' accepting a first argument of type 'System.Data.DataRow' could be found (are you missing a using...
本文介绍了'System.Data.DataRow'不包含'Item'的定义,并且没有扩展方法'Item'可以找到接受类型'System.Data.DataRow'的第一个参数(你是否错过了使用...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
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();
//int[][] polygon=new int[][];
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++)
{
//int result;
//if you want to get the string
DataRow thisRow = (DataRow)dtExcelRecords.Rows[i];
DataTable dt = new DataTable();
dt.Columns.Add("X", typeof(int));
dt.Columns.Add("Y", typeof(int));
txtArea .Text = (CalculatePolygon_Area(dt)).ToString();
}
}
}
public double CalculatePolygon_Area(DataTable Poly_Table)
{
double Poly_Area1;
double Poly_Area2;
double Poly_Area;
int i;
int Count;
Count = (Poly_Table.Rows.Count - 1);
i = 0;
Poly_Area = 0;
Poly_Area1 = 0;
Poly_Area2 = 0;
for (i = 0; (i <= (Poly_Table.Rows.Count - 1)); i++)
{
if ((i == Count))
{
Poly_Area1 = (Poly_Area1
+ (Poly_Table.Rows[i].Item[0] * Poly_Table.Rows[0].Item[1]));
Poly_Area2 = (Poly_Area2
+ (Poly_Table.Rows[i].Item[1] * Poly_Table.Rows[0].Item[0]));
}
else
{
Poly_Area1 = (Poly_Area1
+ (Poly_Table.Rows[i].Item[0] * Poly_Table.Rows[(i + 1)].Item[1]));
Poly_Area2 = (Poly_Area2
+ (Poly_Table.Rows[i].Item[1] * Poly_Table.Rows[(i + 1)].Item[0]));
}
}
Poly_Area = ((Poly_Area1 - Poly_Area2)
/ 2);
return Poly_Area;
}
}
[edit]已添加代码块 - OriginalGriff [/ edit]
[edit]Code block added - OriginalGriff[/edit]
推荐答案
尝试更改:
Try changing:
Poly_Area1 = (Poly_Area1 + (Poly_Table.Rows[i].Item[0] * Poly_Table.Rows[0].Item[1]));
收件人:
To:
Poly_Area1 = (Poly_Area1 + (Poly_Table.Rows[i][0] * Poly_Table.Rows[0][1]));
您可能必须先将值转换为适当的数据类型!
You will probably have to cast the values to an appropriate datatype first!
这篇关于'System.Data.DataRow'不包含'Item'的定义,并且没有扩展方法'Item'可以找到接受类型'System.Data.DataRow'的第一个参数(你是否错过了使用...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文