错误2'System.Data.DataRow'不包含'Item'的定义,并且没有扩展方法'Item'可以找到类型'System.Data.DataRow'的第一个参数(你错过了......) [英] Error 2 '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...
本文介绍了错误2'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))
{
am getting error here // 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
{
am getting error here // 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;
}
}
推荐答案
重复发布相同的问题!
正如您上次发布此消息时所说:
尝试更改:
Stop posting the same question repeatedly!
As you were told the last time you posted this:
Try changing:
Poly_Area1 = (Poly_Area1 + (Poly_Table.Rows[i].Item[0] * Poly_Table.Rows[0].Item[1]));
To:
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!
Remember the last bit this time!
You do know how to cast values I assume? No?
Try this:
Poly_Area1 = (Poly_Area1 + ((double) Poly_Table.Rows[i][0] * (double) Poly_Table.Rows[0][1]));
这篇关于错误2'System.Data.DataRow'不包含'Item'的定义,并且没有扩展方法'Item'可以找到类型'System.Data.DataRow'的第一个参数(你错过了......)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文