C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » .NET »

window service in 3.5


Posted Date: 04 Dec 2008      Posted By: Rajiv Sharma      Member Level: Gold     Points: 1   Responses: 1



hello
i m creating a window service in which i want whole data of excel sheet in to data set (used in code of service).how can i get whole data of excel sheet in to my data set plz give code

thanx





Responses

Author: Santhi    04 Dec 2008Member Level: GoldRating: 2 out of 52 out of 5     Points: 5

Hi,

Use this code

public System.Data.DataSet getCSVData(string fn, bool HDRused)
{
string myConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
+ System.IO.Path.GetDirectoryName(fn)
+ ";Extended Properties=\"text;";

if (HDRused)
{
myConnectionString += "HDR=YES;";
}

else
{
myConnectionString += "HDR=NO;";
}

myConnectionString += "FMT=Delimited(,);";
myConnectionString += "\"";
System.Data.OleDb.OleDbConnection myConnection = new System.Data.OleDb.OleDbConnection();
myConnection.ConnectionString = myConnectionString;
myConnection.Open();
string myCommand = "SELECT * FROM " + System.IO.Path.GetFileName(fn);
System.IO.Path.GetFileName(fn).Replace(".", "#");
System.Data.OleDb.OleDbDataAdapter myDataAdapter = new System.Data.OleDb.OleDbDataAdapter(myCommand, myConnection);
System.Data.DataSet myData = new System.Data.DataSet();
myDataAdapter.Fill(myData);

if (myConnection.State != System.Data.ConnectionState.Closed)
{
myConnection.Close();
}

return(myData);
}

Hope this code helps you.



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : Deletegates
Previous : Windows service with Local system Account
Return to Discussion Forum
Post New Message
Category: .NET

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use