vs2015怎么连接mysql

vs2015怎么连接mysql,第1张

vs2015连接mysql方法:

一.点开工具中的连接到数据库

二.复制sql数据库的服务器名到vs中

三.选择连接的数据库名称

四.选择高级属性最下面的一行全部复制 得到 Data Source = DESKTOP - DFOPNE4Integrated Security = True

五.点开web.config,把复制到字符串的替换到ConnectionString的引号部位中

六.这时就有两种连接方式可以选择了

static string strcon = "server=DESKTOP-DFOPNE4Integrated Security=SSPIdatabase=Library"

SqlConnection con = new SqlConnection(strcon)

找到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://54852.com/sjk/9239021.html

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

发表评论

登录后才能评论

评论列表(0条)

    保存