[TXT]
String constr = @ "provider = Microsoft. jet. oledb.4.0; Data Source = "+ vsfilepath +"; extended properties = 'text; HDR = yes; FMt = delimited; IMEX = 1 ;'";
Oledbdataadapter da = new oledbdataadapter ();
Oledbconnection oconn = new oledbconnection ();
Oconn. connectionstring = constr;
Oconn. open ();
Oledbcommand ocmm = new oledbcommand ();
Ocmm. commandtext = "select * from" + filename + "# TXT ";
Ocmm. Connection = oconn;
Da. selectcommand = ocmm;
Ocmm. commandtimeout = 0;
Try
{
Da. Fill (DS, filename );
}
Catch (exception ex)
{
Throw new exception ("error! "+ Ex. Message. tostring ());
}
Finally
{
Oconn. Close ();
}
[DBF]
String constr = "driver = {Microsoft Visual FoxPro driver}; sourcetype = DBF; sourcedb =" + vsfilepath;
Odbcdataadapter da = new odbcdataadapter ();
Odbcconnection oconn = new odbcconnection ();
Oconn. connectionstring = constr;
Oconn. open ();
Odbccommand ocmm = new odbccommand ();
Ocmm. commandtext = "select" + fcol + "from" + filename;
Ocmm. Connection = oconn;
Da. selectcommand = ocmm;
Ocmm. commandtimeout = 0;
Try
{
Da. Fill (DS, filename );
}
Catch (exception ex)
{
Throw new exception ("error! "+ Ex. Message. tostring ());
}
Finally
{
Oconn. Close ();
}
[XLS]
String constr = @ "provider = Microsoft. jet. oledb.4.0; Data Source = "+ vsfilepath + newnm +"; extended properties = 'excel 8.0; HDR = yes; IMEX = 1 '";
Oledbdataadapter da = new oledbdataadapter ();
Oledbconnection oconn = new oledbconnection ();
Oconn. connectionstring = constr;
Oconn. open ();
Oledbcommand ocmm = new oledbcommand ();
Ocmm. commandtext = "select * from [sheet1 $]";
Ocmm. Connection = oconn;
Da. selectcommand = ocmm;
Ocmm. commandtimeout = 0;
Try
{
Da. Fill (DS, filename );
}
Catch (exception ex)
{
Throw new exception ("error! "+ Ex. Message. tostring ());
}
Finally
{
Oconn. Close ();
}