本文整理汇总了C#中SQLiteConnection.Open方法的典型用法代码示例。如果您正苦于以下问题:C# SQLiteConnection.Open方法的具体用法?C# SQLiteConnection.Open怎么用?C# SQLiteConnection.Open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQLiteConnection
的用法示例。
在下文中一共展示了SQLiteConnection.Open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MultipleResultSets
public void MultipleResultSets()
{
using (SQLiteConnection conn = new SQLiteConnection(m_csb.ConnectionString))
{
conn.Open();
conn.ExecuteNonQuery(@"create table Test(Id integer not null primary key autoincrement, Value text not null);");
conn.ExecuteNonQuery(@"insert into Test(Id, Value) values(1, 'one'), (2, 'two');");
using (var cmd = (SQLiteCommand) conn.CreateCommand())
{
cmd.CommandText = @"select Value from Test where Id = @First; select Value from Test where Id = @Second;";
cmd.Parameters.Add("First", DbType.Int64).Value = 1L;
cmd.Parameters.Add("Second", DbType.Int64).Value = 2L;
using (var reader = cmd.ExecuteReader())
{
Assert.IsTrue(reader.Read());
Assert.AreEqual("one", reader.GetString(0));
Assert.IsFalse(reader.Read());
Assert.IsTrue(reader.NextResult());
Assert.IsTrue(reader.Read());
Assert.AreEqual("two", reader.GetString(0));
Assert.IsFalse(reader.Read());
Assert.IsFalse(reader.NextResult());
}
}
}
}
示例2: openDatabase
public void openDatabase(string options)
{
string[] optVal = getOptVal(options);
if (optVal == null)
{
DispatchCommandResult(new PluginResult(PluginResult.Status.JSON_EXCEPTION));
}
else
{
try
{
string name = optVal[0];
string version = optVal[1];
string display_name = optVal[2];
string size = optVal[3];
db = new SQLiteConnection(name);
db.Open();
DispatchCommandResult(new PluginResult(PluginResult.Status.OK));
}
catch (Exception e)
{
DispatchCommandResult(new PluginResult(PluginResult.Status.ERROR, e.StackTrace));
}
}
}
示例3: Main
static void Main(string[] args)
{
//SQLiteConnection.CreateFile("MyDatabase.sqlite");
SQLiteConnection m_dbConnection;
m_dbConnection = new SQLiteConnection("Data Source=MyDatabase.sqlite;Version=3;");
m_dbConnection.Open();
string sql = "create table highscores (name varchar(20), score int)";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
sql = "insert into highscores (name, score) values ('Me', 3000)";
command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
sql = "insert into highscores (name, score) values ('Myself', 6000)";
command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
sql = "insert into highscores (name, score) values ('And I', 9001)";
command = new SQLiteCommand(sql, m_dbConnection);
command.ExecuteNonQuery();
sql = "select * from highscores order by score desc";
command = new SQLiteCommand(sql, m_dbConnection);
SQLiteDataReader reader = command.ExecuteReader();
while (reader.Read())
Console.WriteLine("Name: " + reader["name"] + "\tScore: " + reader["score"]);
}
示例4: init
private void init(string connString)
{
connection = new SQLiteConnection(connString);
connection.Open();
//connection.ChangeDatabase(Server.MySQLDatabaseName);
transaction = connection.BeginTransaction();
}
示例5: DependentCommands
public void DependentCommands()
{
using (SQLiteConnection conn = new SQLiteConnection(m_csb.ConnectionString))
{
conn.Open();
conn.ExecuteNonQuery(@"create table Test(Id integer not null primary key autoincrement, Value text not null);
create index Test_Value on Test(Value);");
}
}
示例6: fill
internal static void fill(string queryString, DataTable toReturn)
{
using (var conn = new SQLiteConnection(SQLite.connString)) {
conn.Open();
using (SQLiteDataAdapter da = new SQLiteDataAdapter(queryString, conn)) {
da.Fill(toReturn);
}
conn.Close();
}
}
示例7: execute
internal static void execute(string queryString)
{
using (var conn = new SQLiteConnection(SQLite.connString)) {
conn.Open();
using (SQLiteCommand cmd = new SQLiteCommand(queryString, conn)) {
cmd.ExecuteNonQuery();
conn.Close();
}
}
}
示例8: getCurrentAcntPeriod
public string getCurrentAcntPeriod()
{
SQLiteConnection sqlCon = new SQLiteConnection();
sqlCon.ConnectionString = myConfig.connstr;
SQLiteCommand sqLiteCommand1 = new SQLiteCommand();
sqLiteCommand1.CommandText = @"Select acnt_period from configuration";
sqLiteCommand1.CommandType = CommandType.Text;
sqLiteCommand1.Connection = sqlCon;
sqlCon.Open();
return sqLiteCommand1.ExecuteScalar().ToString();
}
示例9: xeqSQL
void xeqSQL(string script)
{
Devart.Data.SQLite.SQLiteConnection sqLiteConnection1 = new SQLiteConnection();
sqLiteConnection1.ConnectionString = myConfig.connstr;
SQLiteCommand sqLiteCommand1 = new SQLiteCommand();
sqLiteCommand1.CommandText = script;
sqLiteCommand1.CommandType = CommandType.Text;
sqLiteCommand1.Connection = sqLiteConnection1;
sqLiteConnection1.Open();
sqLiteCommand1.ExecuteNonQuery();
sqLiteConnection1.Close();
}
示例10: GetMeetings
public static ObservableCollection<MeetingParticipant> GetMeetings(string EventId, string AttendeeWantId)
{
ObservableCollection<MeetingParticipant> Meetings = new ObservableCollection<MeetingParticipant>();
SQLiteConnection sqlCon = new SQLiteConnection(Utilities.GetConnectionString());
SQLiteCommand sqlCmd = new SQLiteCommand("SELECT * FROM Meetings WHERE EventId = @EventId AND AttendeeWantId = @AttendeeWantId", sqlCon);
sqlCmd.Parameters.AddWithValue("@EventId", EventId);
sqlCmd.Parameters.AddWithValue("@AttendeeWantId", AttendeeWantId);
try
{
sqlCon.Open();
SQLiteDataReader reader = sqlCmd.ExecuteReader();
if (reader.HasRows)
{
while (reader.Read())
{
MeetingParticipant ThisMeeting = new MeetingParticipant();
ThisMeeting.MeetingId = reader.GetInt32(0);
ThisMeeting.Id = reader.GetString(2);
ThisMeeting.Name = reader[3] != DBNull.Value ? reader.GetString(3) : string.Empty;
ThisMeeting.CompanyName = reader[4] != DBNull.Value ? reader.GetString(4) : string.Empty;
ThisMeeting.Role = reader[5] != DBNull.Value ? reader.GetString(5) : string.Empty;
ThisMeeting.Status = reader[6] != DBNull.Value ? reader.GetString(6) : string.Empty;
ThisMeeting.IsWalkin = reader.GetBoolean(7);
ThisMeeting.JobTitle = reader[8] != DBNull.Value ? reader.GetString(8) : string.Empty;
ThisMeeting.AllocatedTable = reader[9] != DBNull.Value ? reader.GetString(9) : string.Empty;
ThisMeeting.MeetingSlotStartTime = reader.GetDateTime(11);
ThisMeeting.MeetingSlotEndTime = reader.GetDateTime(12);
ThisMeeting.IsPrimary = reader.GetBoolean(13);
ThisMeeting.TableName = reader.GetString(14);
Meetings.Add(ThisMeeting);
}
}
}
catch (Exception ex)
{
string Meesage = ex.Message;
}
finally
{
sqlCon.Close();
}
return Meetings;
}
示例11: OpenDatabase
static IX509CertificateDatabase OpenDatabase (string fileName)
{
var builder = new SQLiteConnectionStringBuilder ();
builder.DateTimeFormat = SQLiteDateFormats.Ticks;
builder.DataSource = fileName;
if (!File.Exists (fileName))
SQLiteConnection.CreateFile (fileName);
var sqlite = new SQLiteConnection (builder.ConnectionString);
sqlite.Open ();
return new SqliteCertificateDatabase (sqlite, "password");
}
示例12: Dispose
public void Dispose()
{
using (var conn = new SQLiteConnection(m_csb.ConnectionString))
{
conn.Open();
conn.Execute("create table Test (Id int primary key);");
using (var trans = conn.BeginTransaction())
{
conn.Execute("insert into Test(Id) values(1)", transaction: trans);
}
using (var cmd = new SQLiteCommand(@"select count(Id) from Test", conn))
Assert.AreEqual(0L, (long) cmd.ExecuteScalar());
}
}
示例13: AddMeetingsDB
public static void AddMeetingsDB(ObservableCollection<MobileMeetingProject.EsEngine.AttendeeWrapper> Attendees, string EventId)
{
DeleteMeetingsDB(EventId);
foreach (AttendeeWrapper TempAtt in Attendees)
{
foreach (MeetingParticipant ThisMeeting in TempAtt.Meetings)
{
SQLiteConnection sqlCon = new SQLiteConnection(Utilities.GetConnectionString());
SQLiteCommand sqlCmd = new SQLiteCommand("INSERT INTO Meetings(MeetingId,EventId,Id,Name,CompanyName,Role,Status,IsWalkin,JobTitle,AllocatedTable,"+
"AttendeeWantId,StartTime,EndTime,IsPrimary,TableName) VALUES(@MeetingId,@EventId,@Id,@Name,@CompanyName,@Role,"+
"@Status,@IsWalkin,@JobTitle,@AllocatedTable,@AttendeeWantId,@StartTime,@EndTime,@IsPrimary,@TableName)", sqlCon);
sqlCmd.Parameters.AddWithValue("@MeetingId", ThisMeeting.MeetingId);
sqlCmd.Parameters.AddWithValue("@EventId", EventId);
sqlCmd.Parameters.AddWithValue("@Id", ThisMeeting.Id);
sqlCmd.Parameters.AddWithValue("@Name", ThisMeeting.Name);
sqlCmd.Parameters.AddWithValue("@CompanyName", ThisMeeting.CompanyName);
sqlCmd.Parameters.AddWithValue("@Role", ThisMeeting.Role);
sqlCmd.Parameters.AddWithValue("@Status", ThisMeeting.Status);
sqlCmd.Parameters.AddWithValue("@IsWalkin", ThisMeeting.IsWalkin);
sqlCmd.Parameters.AddWithValue("@JobTitle", ThisMeeting.JobTitle);
sqlCmd.Parameters.AddWithValue("@AllocatedTable", ThisMeeting.AllocatedTable);
sqlCmd.Parameters.AddWithValue("@AttendeeWantId", TempAtt.ThisAttendee.Id);
sqlCmd.Parameters.AddWithValue("@StartTime", ThisMeeting.MeetingSlotStartTime);
sqlCmd.Parameters.AddWithValue("@EndTime", ThisMeeting.MeetingSlotEndTime);
sqlCmd.Parameters.AddWithValue("@IsPrimary", ThisMeeting.IsPrimary);
sqlCmd.Parameters.AddWithValue("@TableName", ThisMeeting.TableName);
try
{
sqlCon.Open();
int RowsAffected = sqlCmd.ExecuteNonQuery();
}
catch (Exception ex)
{
string Message = ex.Message;
}
finally
{
sqlCon.Close();
}
}
}
}
示例14: Main
static void Main(string[] args)
{
string file = "test.db";
FileStream fs = new FileStream(file, FileMode.OpenOrCreate);
fs.Close();
var str = string.Format("Data Source={0};Pooling=true;FailIfMissing=false", file);
using (SQLiteConnection conn = new SQLiteConnection(str))
{
//System.CodeDom.CodeBinaryOperatorType
conn.Open();
var param = Console.ReadLine();
var cmd = Console.ReadLine();
//LanguageHelper.AnalysisSentence(cmd, param);
//var insert = ExcuteSqlCmd(conn, string.Format(insertResponse, new object[] { "'" + param + "'", "'" + param + "'" }));
//if (insert == false)
//{
// ExcuteSqlCmd(conn, createTmpMemoTab);
// ExcuteSqlCmd(conn, string.Format(insertResponse, new object[] { "'" + param + "'", "'" + param + "'" }));
//}
}
}
示例15: ReadOnly
public void ReadOnly()
{
using (SQLiteConnection conn = new SQLiteConnection(m_csb.ConnectionString))
{
conn.Open();
conn.Execute("create table Test (TestId int primary key);");
}
File.SetAttributes(m_path, FileAttributes.ReadOnly);
using (SQLiteConnection conn = new SQLiteConnection(m_csb.ConnectionString))
{
try
{
conn.Open();
Assert.Fail("Didn't throw exception");
}
catch (SQLiteException ex)
{
Assert.AreEqual((int) SQLiteErrorCode.ReadOnly, ex.ErrorCode);
}
}
m_csb.ReadOnly = true;
using (SQLiteConnection conn = new SQLiteConnection(m_csb.ConnectionString))
{
try
{
conn.Open();
}
catch (SQLiteException ex)
{
Assert.Fail("Threw exception: {0}", ex.Message);
}
}
File.SetAttributes(m_path, FileAttributes.Normal);
File.Delete(m_path);
}