Click here to Skip to main content
15,896,269 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
01/04/2013
SCRIPCODE SCRIP NAME CAPITAL(No. of shares in lacs)
500002 ABB Ltd. 2119.08375
500003 Aegis Logistics Ltd. 334.29687

I want to read data from above excel

Date is seperately in above excel below that are col names and below that are values for column.
How can i read data from excel where only val for Date column is there?
used below code to read
public void impPennyStockBSEBulkFile(string FilePath, int eximID)
{
try
{
DataSet ds = o_Cls_Utility.ReadExcelToDataSet(FilePath, "SHEET1", "F3", true);

DateTime[] dDate = (from row in ds.Tables[0].AsEnumerable()
select Convert.ToDateTime(row["0"])).ToArray();

string[] strSCRIP_CODE = ds.Tables[0]
.AsEnumerable()
.Select(row => row.Field<string>("SCRIPCODE").Trim())
.ToArray();

string[] strSCRIP_NAME = ds.Tables[0]
.AsEnumerable()
.Select(row => row.Field<string>("SCRIP NAME").Trim())
.ToArray();

double[] dCAPITAL = (from row in ds.Tables[0].AsEnumerable()
select Convert.ToDouble("CAPITAL")).ToArray();


int[] neximID = (from row in ds.Tables[0].AsEnumerable()
select Convert.ToInt32(eximID)).ToArray();

OracleConnect o_Cls_OracleConnect = new OracleConnect();
o_Cls_OracleConnect.OracleCommand_BulkInsert_PreInit();

o_Cls_OracleConnect.OracleCommand_Date_AddParameters(0, "sBulkDate", dDate);
o_Cls_OracleConnect.OracleCommand_Varchar2_AddParameters(1, "sScripCode", strSCRIP_CODE);
o_Cls_OracleConnect.OracleCommand_Varchar2_AddParameters(2, "sScripName", strSCRIP_NAME);
o_Cls_OracleConnect.OracleCommand_Double_AddParameters(3, "sCapital", dCAPITAL);
o_Cls_OracleConnect.OracleCommand_Number_AddParameters(4, "nEXIM_ID", neximID);


int recordsInserted = o_Cls_OracleConnect.OracleCommand_BulkInsert(strSCRIP_CODE.Length, "SP_PENNYSTOCK_BSE_BULKFILE_IMP");
o_Cls_OracleConnect.Dispose();
}

and in dataset only below val are shown

SCRIPCODE SCRIP NAME CAPITAL(No. of shares in lacs)
500002 ABB Ltd. 2119.08375
500003 Aegis Logistics Ltd. 334.29687
Posted
Updated 18-Sep-13 21:45pm
v2
Comments
RDBurmon 19-Sep-13 7:34am    
Is you sheet contain only one date value or multiple date values ?

This Code Works In c#





if (FileUpload1.FileName.ToString() == "")
{
lblMsg.Text = "Please Select File (.xls)";
return;
}

string filExt =
FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.LastIndexOf(".") + 1);
if (filExt.ToUpper() != "XLS")
{
lblMsg.Text = "Only Excel files are supported.";
FileUpload1.Focus();
return;
}
try
{
string strSQL = "";
string bank="",CR="",DR="",Bal="";
DateTime EDOE;
int i = 0;
string FPath = Server.MapPath("~/PostReceive/BankFiles/");
FPath = FPath + System.DateTime.Now.Date.ToString("dd-MMM-yyyy") + ".xls";
FileUpload1.PostedFile.SaveAs(FPath);
lblMsg.Text = "";
string connstr = "Provider=Microsoft.Jet.Oledb.4.0;Data Source=" + FPath + ";
Extended Properties=Excel 8.0";
OleDbConnection conn = new OleDbConnection(connstr);
OleDbCommand cmd;
DataSet ds = new DataSet();
OleDbDataAdapter da;
OleDbCommand cmd1 = new OleDbCommand();
DataSet ds1 = new DataSet();
OleDbDataAdapter da1 = new OleDbDataAdapter();
lblTotal.Text = "0.0";

strSQL = " SELECT Name,Description,ChequeNo,DR,CR,BAL,format(TRDate,'dd-MMM-yyyy')
as TDate FROM [NARAYAN$]"; // Here NARAYAN is Excel Sheet Name
cmd = new OleDbCommand(strSQL, conn);// Column in sheet
// Name,Description,ChequeNo,DR,CR,BAL

da = new OleDbDataAdapter(cmd);
da.Fill(ds, "NTable");
 
Share this answer
 
v2
 
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