2 如服务正常启动,打开sqlserver管理器,看看里面的实例数据库是否能正常访问
3 如上述都正常,检查下你vs2015连接时是否选对正确的实例数据库名
找到C#下SQLite *** 作驱动dll并下载:System.Data.SQLite
在项目中添加dll的引用
创建数据库(文件):
SQLiteConnection.CreateFile("MyDatabase.sqlite")
连接数据库:
SQLiteConnection m_dbConnection=new SQLiteConnection("Data Source=MyDatabase.sqliteVersion=3")
m_dbConnection.Open()
插入数据:
String sql = "insert into highscores (name, score) values ('Me', 3000)"
SQLiteCommand 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()
查询:
string sql = "select * from highscores order by score desc"
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection)
SQLiteDataReader reader = command.ExecuteReader()
while (reader.Read())
Console.WriteLine("Name: " + reader["name"] + "\tScore: " + reader["score"])
Console.ReadLine()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)