Create an Access database, and create tables and data. Important: Close Access database references

Source: Internet
Author: User

 /// <summary>        ///Create an Access database, and create tables and data/// </summary>        /// <param name= "dicttable" ></param>        /// <param name= "FilePath" ></param>        /// <returns></returns>         Public intDatatabletoaccess (dictionary<string, Datatable> dicttable,stringFilePath) {            intCount =0; stringConnStr =string. Format ("Provider=Microsoft.Jet.OLEDB.4.0;Data source={0}; Jet Oledb:engine type=5", FilePath); Try{ADOX. Catalog Catalog=NewADOX.                Catalog (); Catalog.   Create (CONNSTR); //Create an Access databaseADODB. Connection cn=NewADODB.                Connection (); cn. Open (ConnStr,NULL,NULL, -1); Catalog. ActiveConnection=cn; foreach(varIteminchdicttable) {ADOX. Table Table=NewADOX.                    Table (); Table. Name=item.                    Key; foreach(DataColumn Cinchitem. value.columns) {table.                    Columns.Append (C.columnname, Datatypeenum.adlongvarwchar); } catalog.                Tables.append (table); }                #regionRelease COM-referenced object "This code block runs in release mode is valid"System.Runtime.InteropServices.Marshal.ReleaseComObject (catalog);                System.Runtime.InteropServices.Marshal.FinalReleaseComObject (catalog); Catalog=NULL; cn.                Close (); Gc.                WaitForPendingFinalizers (); Gc.                Collect (); #endregion            }            Catch(Exception ex) {Throwex; }            foreach(varIteminchdicttable) {StringBuilder Sbcolumns=NewStringBuilder (); StringBuilder sbvalues=NewStringBuilder (); Sbcolumns.append ("INSERT INTO ["+ Item. Key +"]("); foreach(DataColumn Cinchitem. Value.columns) {sbcolumns.append ("["+ C.columnname +"],"); } sbcolumns.remove (Sbcolumns.length-1,1); Sbcolumns.append (")"); foreach(DataRow rowinchitem.                    Value.rows) {sbvalues.append (sbcolumns.tostring ()); Sbvalues.append ("VALUES ("); foreach(DataColumn Cinchitem. Value.columns) {sbvalues.append ("'"+ Commutils.dtrowfilter (Row[c.columnname] +"") +"',"); } sbvalues.remove (Sbvalues.length-1,1); Sbvalues.append (");"); Sbvalues.appendline (""); //using (dbhelperaccess access = new Dbhelperaccess (connstr))//{dbhelperaccess Access =Newdbhelperaccess (CONNSTR); //dbhelperaccess access = new Dbhelperaccess (CONNSTR);access.                    Executesqlnonquery (Sbvalues.tostring ()); Access.                    Conn.dispose (); Access=NULL; //}sbvalues.clear (); } GC.            Collect (); }            returncount; }

The

Creates an Access database and creates tables and data. Important: Close the Access database reference

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.