vs2015怎么添加数据库

vs2015怎么添加数据库,第1张

1 先去服务检查下你的sqlserver是否已启动

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()


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/10086032.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-05
下一篇 2023-05-05

发表评论

登录后才能评论

评论列表(0条)

保存