欢迎您访问365答案网,请分享给你的朋友!
生活常识 学习资料

c#java同理连接数据库获取某张表内容数量

时间:2023-06-10

参考文章参考

class db { private SQLiteConnection dbConnection; //private SQLiteCommand cd; //private SQLiteDataReader read; public SQLiteConnection lian(string path) { //创建连接字符串 try { string databaseFileName = path; string connectionString = "data source = " + databaseFileName; //链接数据库 dbConnection = new SQLiteConnection(connectionString); dbConnection.Open(); } catch (Exception e) { Console.Write(e + "对象"); } return dbConnection; } }db b= new db(); //创建连接字符串 string path="C:/QQ.db";string count; string sqlc = "select count(*) as num from '" + str + "';"; //加载sql SQLiteCommand cdsc = new SQLiteCommand(sqlc, b.lian(path)); //执行 SQLiteDataReader drc = cdsc.ExecuteReader(); if (drc.Read()) { count = drc["num"].ToString(); Console.Write(count); }

Copyright © 2016-2020 www.365daan.com All Rights Reserved. 365答案网 版权所有 备案号:

部分内容来自互联网,版权归原作者所有,如有冒犯请联系我们,我们将在三个工作时内妥善处理。