Use Access as a back-end database support.

Source: Internet
Author: User

<summary>

Reading an Excel document

</summary>

<param name= "Path" > File name </param>

<returns> Returns a dataset </returns>

Public DataSet exceltods (string Path)

{String strconn = "provider=microsoft.jet.oledb.4.0;" + "Data source=" + Path + ";" + "Extended Properties=excel 8.0;"; OleDbConnection conn = new OleDbConnection (strconn); Conn. Open (); String strexcel = ""; OleDbDataAdapter mycommand = null; DataSet ds = null; Strexcel= "SELECT * from [sheet1$]"; mycommand = new OleDbDataAdapter (Strexcel, strconn); ds = new DataSet (); Mycommand.fill (ds, "Table1"); return DS; }

<summary>

Writing to an Excel document

</summary>

<param name= "Path" > File name </param> public bool Savefp2toexcel (string Path) {try {string strconn = "Provider =microsoft.jet.oledb.4.0; "+" Data source= "+ Path +"; " + "Extended Properties=excel 8.0;"; OleDbConnection conn = new OleDbConnection (strconn); Conn. Open (); System.Data.OleDb.OleDbCommand cmd=new OleDbCommand ();

Cmd. Connection =conn; Cmd.commandtext = "Update [sheet1$] SET name = ' 2005-01-01 ' WHERE work number = ' Date '";

Cmd. ExecuteNonQuery ();

for (int i=0;i<fp2. Sheets [0]. rowcount-1;i++) {

if (FP2. Sheets [0]. cells[i,0]. Text!= "") {

Cmd.commandtext = "INSERT into [sheet1$] (work number, name, department, title, date, time) VALUES ('" +FP2. Sheets [0]. cells[i,0]. text+ "', '" + FP2. Sheets [0]. cells[i,1]. text+ "', '" +FP2. Sheets [0]. cells[i,2]. text+ "', '" +FP2. Sheets [0]. cells[i,3]. text+ "', '" +FP2. Sheets [0]. cells[i,4]. text+ "', '" +FP2. Sheets [0]. cells[i,5]. text+ "')"; Cmd. ExecuteNonQuery (); }

} conn. Close (); return true; }

catch (System.Data.OleDb.OleDbException ex) {

System.Diagnostics.Debug.WriteLine ("Write Excel Error:" +ex. Message); }

return false;

}

Use Access as a back-end database support.

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.