Public Dataset filldataset ()
{
Sqlconnection Conn = New Sqlconnection ( " Server = (local); Integrated Security = true; initial catalog = master; " );
Sqlcommand cmd = New Sqlcommand ( " Select [name], [filename] From DBO. sysdatabases " , Conn );
Sqldataadapter da = New Sqldataadapter (CMD );
Dataset DS= NewDataset ();
Try
{
Conn. open ();
Try
{
Da. Fill (DS ); // Fill dataset with data
}
Catch (Exception)
{
Return Null ;
}
Finally
{
Conn. Close ();
Conn. Dispose ();
}
}
Catch (Exception)
{
Return Null ;
}
Return DS;
} Private Datatable filldatatablebyaccess ()
{
String Connstring = " Provider = Microsoft. Jet. oledb.4.0; Data Source = \ "" + System. Io. Path. getfullpath ( " Db1.mdb " ) + " \ "" ;
System. Data. oledb. oledbconnection oledbconn = New System. Data. oledb. oledbconnection (connstring );
System. Data. oledb. oledbcommand oledbcom = New System. Data. oledb. oledbcommand ( " Select * from customer table " , Oledbconn );
System. Data. oledb. oledbdataadapter oledbdr = New System. Data. oledb. oledbdataadapter (oledbcom );
Datatable dt= NewDatatable ();
Try
{
Oledbconn. open ();
Try
{
Oledbdr. Fill (DT );
}
Catch (Exception exc)
{
MessageBox. Show (EXC. Message );
}
Finally
{
Oledbconn. Close ();
Oledbconn. Dispose ();
}
}
Catch (Exception exc)
{
MessageBox. Show (EXC. Message );
}
ReturnDT;
}