.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Forum >> C# >> Post New QuestionBookmark and Share Subscribe to Forum

Unable to Read Integers From XL Sheet Using C#

Posted By: Karthik     Posted Date: September 19, 2013    Points:5   Category :C#
Hi ,

Please help me in reading all the values from excel sheet and store it in the D/B. I'm able to retrieve and store alphanumeric values from excel sheet but not able to retrieve numbers. I'm using below code

string ssqltable = "HulaminLtd";
string myexceldataquery = "select * from [Sheet1$]";

string sexcelconnectionstring = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + excelfilepath + ";" + "Extended Properties=Excel 8.0;";
string ssqlconnectionstring = "Data Source=ROHITHVYAS;Initial Catalog=SRDR;User ID=sa;Password=testkar";
string sclearsql = "delete from " + ssqltable;
SqlConnection sqlconn = new SqlConnection(ssqlconnectionstring);
SqlCommand sqlcmd = new SqlCommand(sclearsql, sqlconn);
sqlconn.Open();
sqlcmd.ExecuteNonQuery();

OleDbConnection oledbconn = new OleDbConnection(sexcelconnectionstring);
OleDbCommand oledbcmd = new OleDbCommand(myexceldataquery, oledbconn);
oledbconn.Open();
OleDbDataAdapter oleda = new OleDbDataAdapter(oledbcmd);
DataSet ds = new DataSet();
oleda.Fill(ds);


Int64 rowsCount = ds.Tables[0].Rows.Count;
DataTable dt = ds.Tables[0];


for (int i = dt.Rows.Count; i >= 0; i--)
{
if (i <= 13)
{
DataRow drrow = dt.Rows[i];
dt.Rows.Remove(drrow);
}

}
dt.AcceptChanges();
SqlBulkCopy bulkcopy = new SqlBulkCopy(ssqlconnectionstring);
bulkcopy.DestinationTableName = ssqltable;
bulkcopy.WriteToServer(dt);
sqlconn.Close();
oledbconn.Close();

Responses

No response found. Be the first to respond this post
Post Reply

You must Sign In To post reply
 
 
Find more Forum Questions on C#, ASP.Net, Vb.Net, SQL Server and more Here
Quick Links For Forum Categories:
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  OOPs  SilverlightIISJQuery
JavaScript/VBScriptBiztalkWPFPatten/PracticesWCFOthers
www.DotNetSpark.comUnAnsweredAll

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend