-----------------------------------------------------------
New Message on BDOTNET
-----------------------------------------------------------
From: ChiefCoder
Message 6 in Discussion
Hi Sara
Refer to code below: Method ReadCSV will return object of type DataSet that you can
then hook with your SQL Server or the Presentation. Just pass the file as a parameter
to this method. DataSet ReadCSV(string file)
{
if (! File.Exists(file) )
return null;
DataSet ds = new DataSet();
OleDbConnection conn = null;
string FileConnection = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" +
@Path.GetDirectoryName(file) + ";" + @"Extended Properties=""Text;HDR=YES;""";
try
{
try
{
conn = new OleDbConnection();
conn.ConnectionString = FileConnection;
conn.Open();
}
catch
{
Console.WriteLine("Database connection can't be established");
return null;
}
string sql = String.Format("SELECT * FROM {0}",Path.GetFileName(file));
OleDbDataAdapter oda = new OleDbDataAdapter(sql, conn);
oda.SelectCommand.ExecuteNonQuery();
oda.Fill(ds, "TableName");
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return null;
}
finally
{
if(conn != null)
conn.Dispose();
}
return ds;
}
Regards Sumit
-----------------------------------------------------------
To stop getting this e-mail, or change how often it arrives, go to your E-mail
Settings.
http://groups.msn.com/bdotnet/_emailsettings.msnw
Need help? If you've forgotten your password, please go to Passport Member Services.
http://groups.msn.com/_passportredir.msnw?ppmprop=help
For other questions or feedback, go to our Contact Us page.
http://groups.msn.com/contact
If you do not want to receive future e-mail from this MSN group, or if you received
this message by mistake, please click the "Remove" link below. On the pre-addressed
e-mail message that opens, simply click "Send". Your e-mail address will be deleted
from this group's mailing list.
mailto:[EMAIL PROTECTED]