Click here to Skip to main content
15,908,776 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
C#
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;
    }
    }
Posted
Updated 7-Oct-13 5:53am
v2
Comments
Member 10320674 7-Oct-13 11:43am    
getting error in the line of 88
idenizeni 7-Oct-13 11:57am    
Why the repost?
Check your first post regarding this question...
http://www.codeproject.com/Questions/664707/System-Data-DataRow-does-not-contain-a-definition

OriginalGriff's solution should help you if you know how to cast the values. If not then ask for clarification in the original post.

1 solution

Stop posting the same question repeatedly!

As you were told the last time you posted this:
Try changing:
C#
Poly_Area1 = (Poly_Area1 + (Poly_Table.Rows[i].Item[0] * Poly_Table.Rows[0].Item[1]));
To:
C#
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:
C#
Poly_Area1 = (Poly_Area1 + ((double) Poly_Table.Rows[i][0] * (double) Poly_Table.Rows[0][1]));
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900