Csharp:sqlite and Access using C # code read data

Source: Internet
Author: User
Tags sqlite sqlite database

SQLite SQL script:

CREATE TABLE bookkindlist (bookkindid INTEGER PRIMARY KEY autoincrement,bookkindname varchar ($) NOT NULL,           Bookkindcode varchar (+) null,bookkindparent int null)--add insert into bookkindlist (Bookkindname,bookkindcode, bookkindparent) VALUES (' directory ', ' 0003 ', 1);--Query SELECT * FROM Bookkindlist;select * from Bookkindlist where bookkindlist.bookkindid=2;--Deleting the delete from bookkindlist where bookkindlist.bookkindid=3;--updates the update  bookkindlist Set Bookkindname= ' literature ', bookkindcode= ' 0002 ', bookkindparent=1 where bookkindid=2;--back add self-increment idselect last_insert_rowid () ;

SQLite Database Connection character

<?xml version= "1.0" encoding= "Utf-8"?><configuration> <appSettings> <add key= " Connectionaccess2003string "value=" Provider=Microsoft.Jet.OLEDB.4.0;Data source=| Datadirectory|geovindu.mdb; Persist Security info=true "/> <add key=" connectionaccess2007string "value=" provider=microsoft.ace.oledb.12.0 ;D ATA source=| DATADIRECTORY|GEOVINDU.ACCDB; Persist Security info=true "/> <add key=" connectionsqlstring "value=" Data source=lf-wen\geovindu;initial Catalog =geovindu; User Id=sa; Password=geovindu "/> <add key=" connectionsqlitestring "value=" Data source=geovindu.db3; version=3; Password=geovindu; Pooling=true; Failifmissing=false; " /> <add key= "connectionmysqlstring" value= "database= ' Geovindu ';D ata source= ' 127.0.0.1 '; User id= ' root '; password= ' Geovindu '; charset= ' UTF8 ';p ooling=true; port=3306; Allow Zero datetime=true; " /> <add key= "Webdal" value= "Accessdal"/> <!--<add key= "Webdal" value= "Sqlserverdal"/>--> &lt ;! --<addkey= "Webdal" value= "Sqlsqlitedal"/>--> <!--<add key= "Webdal" value= "Sqlmysqldal"/>--> <!--< Add key= "Webdal" value= "Sqlpostgresqldal"/>--> </appSettings></configuration>

  

CSharp Operation SQLite Add return value

 <summary>///20150212///SQLite add return value ID///</summary>//<param NA Me= "SQLString" ></param>//<param Name= "Identity" ></param>//<param name= "Cmdparm S "></param>///<returns></returns> public static int ExecuteSQL (string SQLString, out            int identity, params sqliteparameter[] cmdparms) {string en = ""; using (sqliteconnection connection = new Sqliteconnection (connectionString)) {using (Sqlitecomm and cmd = new Sqlitecommand ()) {try {Prepare                        Command (cmd, connection, NULL, SQLString, cmdparms); int rows = cmd.                        ExecuteNonQuery (); Cmd.                        Parameters.clear ();                        Cmd.commandtext = "Select Last_insert_rowid ();"; En = cmd. ExecuteScalar ().      ToString ();                  identity = Int.                        Parse (en); Cmd.                        Parameters.clear ();                    return rows; } catch (System.Data.OleDb.OleDbException E) {throw new Exce                    Ption (E.message); }                }            }        }

 <summary>//Recover return value//SQLite tu///</summary>//<param name= "Bookkin        Dlist "></param>//<param name=" id "></param>//<returns></returns>            public int Insertbookkindout (Bookkindlistinfo bookkindlist, out int id) {int ret = 0;            int tid = 0;                try {StringBuilder str = new StringBuilder (); Str.                Append ("INSERT into bookkindlist (bookkindname,bookkindcode,bookkindparent) VALUES ("); Str.                                Append ("@BookKindName, @BookKindCode, @BookKindParent);"); sqliteparameter[] par = new sqliteparameter[]{new sqliteparameter ("@BookKindName", dbtype.string,1000), new                Sqliteparameter ("@BookKindCode", dbtype.string,1000), New Sqliteparameter ("@BookKindParent", dbtype.int32,4),                New Sqliteparameter ("@BookKindID", dbtype.int32,4),}; Par[0]. Value =Bookkindlist.bookkindname; PAR[1].                Value = Bookkindlist.bookkindcode; PAR[2].                Value = bookkindlist.bookkindparent; PAR[3]. Direction = parameterdirection.output;//Invalid does not support RET = Sqlitehelper.executesql (str.                ToString (), out Tid, par); if (Ret > 0) {//tid = ret;//(int) par[3].                Value;            }} catch (Sqliteexception ex) {throw ex;            } id = tid;        return ret; }

CSharp Action Access Add return value

        <summary>///Access adds a return ID value////2014-12-29//Geovin Du///reference: HT Tp://www.mikesdotnetting.com/article/54/getting-the-identity-of-the-most-recently-added-record/HTTP//  stackoverflow.com/questions/186544/identity-after-insert-statement-always-returns-0//</summary>/// <param name= "SQLString" ></param>//<param Name= "Identity" ></param>//<param Name= "cmdparms" ></param>///<returns></returns> public static int ExecuteSQL (String SQ lstring, out int identity, params oledbparameter[] cmdparms) {using (OleDbConnection connect                Ion = new OleDbConnection (connectionString)) {using (OleDbCommand cmd = new OleDbCommand ()) {try {preparecommand (cmd, connection, NULL, SQL               String, cmdparms);         int rows = cmd.                        ExecuteNonQuery ();                        Cmd.commandtext = "SELECT @ @Identity"; identity = (int) cmd.                        ExecuteScalar (); Cmd.                        Parameters.clear ();                    return rows; } catch (System.Data.OleDb.OleDbException E) {throw new Exce                    Ption (E.message); }                }            }        }

        <summary>///Access Append return value///TU///20141205//</summary> <param name= "bookkindlist" ></param>//<param name= "id" ></param>//<retur            ns></returns> public int Insertbookkindout (Bookkindlistinfo bookkindlist, out int id) {            int ret = 0;            int tid = 0;                try {StringBuilder str = new StringBuilder (); Str.                Append ("INSERT into bookkindlist (bookkindname,bookkindcode,bookkindparent) VALUES ("); Str.                Append ("@BookKindName, @BookKindCode, @BookKindParent);");  oledbparameter[] par = new Oledbparameter[]{new OleDbParameter ("@BookKindName", oledbtype.varchar,1000), new OleDbParameter ("@BookKindCode", oledbtype.varchar,1000), New OleDbParameter ("@BookKindParent", oledbtype.integer,4       ),//new oledbparameter ("@BookKindID", oledbtype.integer,4),};         Par[0].                Value = Bookkindlist.bookkindname; PAR[1].                Value = Bookkindlist.bookkindcode; PAR[2].                Value = bookkindlist.bookkindparent; PAR[3]. Direction = parameterdirection.output;//Invalid does not support RET = Dbhelperoledb.executesql (str.                ToString (), out Tid, par); if (Ret > 0) {//tid = ret;//(int) par[3].                Value;            }} catch (OleDbException ex) {throw ex;            } id = tid;        return ret; }

  

Csharp:sqlite and Access using C # code read data

Related Article

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.