62,041
社区成员
发帖
与我相关
我的任务
分享
public static object ExecuteSqlGet(string SQLString, string content)
{
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
{
OpenDb(connection);
using (SQLiteCommand cmd = new SQLiteCommand(SQLString, connection))
{
SQLiteParameter myParameter = new SQLiteParameter("@content", DbType.String);
myParameter.Value = content;
cmd.Parameters.Add(myParameter);
try
{
if (connection.State != ConnectionState.Open)
connection.Open();
object obj = cmd.ExecuteScalar();
if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
{
return null;
}
else
{
return obj;
}
}
catch (System.Data.SQLite.SQLiteException E)
{
throw new Exception(E.Message);
}
finally
{
cmd.Dispose();
connection.Close();
}
}
}
}
public static int ExecuteSqlInsertImg(string strSQL, byte[] fs)
{
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
{
OpenDb(connection);
using (SQLiteCommand cmd = new SQLiteCommand(strSQL, connection))
{
SQLiteParameter myParameter = new SQLiteParameter("@fs", DbType.Binary);
myParameter.Value = fs;
cmd.Parameters.Add(myParameter);
try
{
if (connection.State != ConnectionState.Open)
connection.Open();
int rows = cmd.ExecuteNonQuery();
return rows;
}
catch (System.Data.SQLite.SQLiteException E)
{
throw new Exception(E.Message);
}
finally
{
cmd.Dispose();
connection.Close();
}
}
}
}
public static object GetSingle(string SQLString)
{
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
{
OpenDb(connection);
using (SQLiteCommand cmd = new SQLiteCommand(SQLString, connection))
{
try
{
object obj = cmd.ExecuteScalar();
if ((Object.Equals(obj, null)) || (Object.Equals(obj, System.DBNull.Value)))
{
return null;
}
else
{
return obj;
}
}
catch (System.Data.SQLite.SQLiteException e)
{
//connection.Close();
throw new Exception(e.Message);
}
finally
{
connection.Close();
cmd.Dispose();
}
}
}
}
public static DataSet Query(string SQLString)
{
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
{
OpenDb(connection);
try
{
DataSet ds = new DataSet();
using (SQLiteDataAdapter command = new SQLiteDataAdapter(SQLString, connection))
{
command.Fill(ds, "ds");
}
return ds;
}
catch (System.Data.SQLite.SQLiteException ex)
{
throw new Exception(ex.Message);
}
}
}
public static DataSet Query(string SQLString, string TableName)
{
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
{
OpenDb(connection);
DataSet ds = new DataSet();
try
{
SQLiteDataAdapter command = new SQLiteDataAdapter(SQLString, connection);
using (command)
{
command.Fill(ds, TableName);
}
}
catch (System.Data.SQLite.SQLiteException ex)
{
throw new Exception(ex.Message);
}
return ds;
}
}
public static DataSet Query(string SQLString, int Times)
{
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
{
OpenDb(connection);
DataSet ds = new DataSet();
try
{
SQLiteDataAdapter command = new SQLiteDataAdapter(SQLString, connection);
using (command)
{
command.SelectCommand.CommandTimeout = Times;
command.Fill(ds, "ds");
}
return ds;
}
catch (System.Data.SQLite.SQLiteException ex)
{
throw new Exception(ex.Message);
}
}
}
public static int ExecuteSql(string SQLString, params SQLiteParameter[] cmdParms)
{
using (SQLiteConnection connection = new SQLiteConnection(connectionString))
{
OpenDb(connection);
using (SQLiteCommand cmd = new SQLiteCommand())
{
try
{
PrepareCommand(cmd, connection, null, SQLString, cmdParms);
int rows = cmd.ExecuteNonQuery();
cmd.Parameters.Clear();
return rows;
}
catch (System.Data.SQLite.SQLiteException E)
{
throw new Exception(E.Message);
}
}
}
}