|
Using system;
Using system. text;
Using system. Data;
Using system. Data. SQLite;
Namespace WQ. SQLite. Database
{
// If not, contact the developer QQ: 13164946
// Author: epe521 EML: epe521@qq.com
Public class sqlitedatabase: idisposable
{
Sqliteconnection conn;
Private int itimeout = 30;
Private string strerro;
Private string connstr;
Public sqlitedatabase (string _ connstring)
{
Connstr = _ connstring;
}
Private sqlitecommand createcommand (string sqlstring)
{
This. Open (connstring );
Sqlitecommand command = new sqlitecommand (sqlstring, this. Conn );
Command. commandtimeout = This. Timeout;
Command. commandtype = commandtype. text;
Command. commandtext = sqlstring;
Return command;
}
Public bool excquery (string sqlstring)
{
Try
{
Sqlitecommand command = new sqlitecommand (sqlstring, new sqliteconnection (connstring ));
Command. Connection. open ();
Command. executenonquery ();
Command. Connection. Close ();
Return true;
}
Catch (exception)
{
This. strerro = Exception. tostring ();
Return false;
}
}
Public datatable getdatatable (string sqlstring)
{
Try
{
Sqliteconnection selectconnection = new sqliteconnection (connstring );
Sqlitedataadapter adapter = new sqlitedataadapter (sqlstring, selectconnection );
Dataset dataset = new dataset ();
Adapter. Fill (dataset, "mytable ");
Return dataset. Tables ["mytable"];
}
Catch (exception)
{
This. strerro = sqlstring + "\ n" + exception. message;
Return NULL;
}
}
Public bool getdatatable (string sqlstring, ref datatable)
{
Try
{
Sqliteconnection selectconnection = new sqliteconnection (connstring );
Sqlitedataadapter adapter = new sqlitedataadapter (sqlstring, selectconnection );
Dataset dataset = new dataset ();
Adapter. Fill (dataset, "mytable ");
Datatable = dataset. Tables ["mytable"];
Return true;
}
Catch (exception)
{
This. strerro = sqlstring + "\ n" + exception. message;
Return false;
}
}
Public bool getdatatable (string sqlstring, sqliteparameter [] Pa, ref datatable DT)
{
Try
{
Sqliteconnection selectconnection = new sqliteconnection (connstring );
Sqlitedataadapter adapter = new sqlitedataadapter (sqlstring, selectconnection );
Dataset dataset = new dataset ();
For (INT I = 0; I <Pa. length; I ++)
{
Adapter. selectcommand. Parameters. Add (PA [I]);
}
Adapter. Fill (dataset, "mytable ");
Dt = dataset. Tables ["mytable"];
Return true;
}
Catch (exception)
{
This. strerro = sqlstring + "\ n" + exception. message;
Return false;
}
}
Public bool getdatatable (string sqlstring, int pageindex, int maxrecords, ref datatable)
{
Try
{
Sqliteconnection selectconnection = new sqliteconnection (connstring );
Sqlitedataadapter adapter = new sqlitedataadapter (sqlstring, selectconnection );
Dataset dataset = new dataset ();
Adapter. Fill (dataset, pageindex, maxrecords, "mytable ");
Datatable = dataset. Tables ["mytable"];
Return true;
}
Catch (exception)
{
This. strerro = sqlstring + "\ n" + exception. message;
Return false;
}
}
Public String getonevalue (string sqlstring, sqliteparameter [] Pa)
{
Sqlitecommand command = new sqlitecommand (sqlstring, new sqliteconnection (connstring ));
For (INT I = 0; I <Pa. length; I ++)
{
Command. Parameters. Add (PA [I]);
}
Command. Connection. open ();
String STR = command. executescalar (). tostring ();
Command. Connection. Close ();
Return STR;
}
Public String getonevalue (string connstring, string sqlstring)
{
Sqlitecommand command = This. createcommand (sqlstring );
String STR = command. executescalar (). tostring ();
Command. Connection. Close ();
Return STR;
}
Private void open (string _ connectionstring)
{
If (this. Conn = NULL)
{
This. Conn = new sqliteconnection (_ connectionstring );
This. Conn. open ();
}
Else if (this. Conn. State! = Connectionstate. open)
{
This. Conn. open ();
}
}
Public void close ()
{
If (this. Conn! = NULL)
{
This. Conn. Close ();
}
Else if (this. Conn. State = connectionstate. open)
{
This. Conn. Close ();
}
}
Public void dispose ()
{< br> If (this. Conn! = NULL)
{< br> This. Conn. Dispose ();
This. Conn = NULL;
}< BR >}
Public String errstring
{< br> Get
{< br> return this. strerro;
}< BR >}
private string connstring
{< br> Get
{< br> return this. connstr;
}< br> set
{< br> This. connstr = value;
}< BR >}
Public int timeout
{
Get
{
Return this. itimeout;
}
Set
{
This. itimeout = value;
}
}
}
}
There are also SQL operations, which are absolutely powerful. Hi me if necessary
|