C # access the SQL \ accsee database instance

Source: Internet
Author: User
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;
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.