/// <summary> ///returns the primary key value after insert/// </summary> /// <param name= "SQLString" ></param> /// <param name= "para" ></param> /// <returns></returns> Public Static intExecuteSQL (stringSQLString, list<sqliteparameter>para) { using(Sqliteconnection connection =getsqliteconnection ()) { using(Sqlitecommand cmd =NewSqlitecommand (SQLString, connection)) { Try{connection. Open (); if(para!=NULL) { foreach(Sqliteparameter Pinchpara) {cmd. Parameters.Add (P); } } introws =0; if(Sqlstring.indexof ("Insert") != -1) Rows=Convert.ToInt32 (cmd. ExecuteScalar ()); Elserows=cmd. ExecuteNonQuery (); returnrows; } Catch(sqliteexception e) {connection. Close (); Throwe; } } } }
Note: To be under the same connection, you can
stringsql ="INSERT INTO Ims_tbl_hotelinfo (Hotelid,hotelname,hoteltelephone,hoteladdress,remark,kid,vip,xid,yid,bid,cid, Did,eid,fid,hid) VALUES ('"+ Hotelid +"', '"+ Hotelname +"', '"+ Hotaltelephone +"', '"+ hotaladdress +"', '"+ Hremark +"', ' , ', ', ', ', ', ', ', ', ', ', ')"; intresult = Sqlitedbhelper.executesql (sql +"; select Last_insert_rowid ();",NULL);//return PRIMARY Key