Click here to Skip to main content
14,934,046 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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);
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();
DataTable dtExcelSheetName = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
string getExcelSheetName = dtExcelSheetName.Rows[0]["Table_Name"].ToString();
cmd.CommandText = "SELECT * FROM [" + getExcelSheetName + "]";
dAdapter.SelectCommand = cmd;
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);

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;

[no name] 3-Oct-13 6:47am
'System.Convert' does not contain a definition for 'Toint32'
'System.Convert' does not contain a definition for 'Toint32'
The best overloaded method match for '_Default.polygonArea(int[], int[])' has some invalid arguments
Argument '1': cannot convert from 'int' to 'int[]'
Argument '2': cannot convert from 'int' to 'int[]' these are errors
Anurag Sinha V 3-Oct-13 7:05am
Its Convert.ToInt32..

That is because C# is case sensitive. Try changing:
int X = Convert.Toint32(thisRow["X"]);
int Y = Convert.Toint32 (thisRow["Y"]);
int X = Convert.ToInt32(thisRow["X"]);
int Y = Convert.ToInt32 (thisRow["Y"]);
[no name] 3-Oct-13 7:03am
i write that code only
[no name] 3-Oct-13 7:07am
am using that code only but no use
OriginalGriff 3-Oct-13 7:19am
Show me the exact code that generates the compilation error: copy and paste it.
You can use following conversion method

Int32 n = Int32.Parse();

int n = Convert.ToInt32();


int n = int.Parse();
[no name] 3-Oct-13 7:39am
no use
CHill60 3-Oct-13 12:18pm
Do you get the same error as before? And can you reply to OriginalGriff's request for the exact code

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

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