C# 连接sqlite数据库


 web.config 

<connectionStrings>
<add name="SQLiteDB" connectionString="Data Source=C:\Users\Desktop\test.db"/>
</connectionStrings>

 

 

public class ProductService
{
public static readonly ProductService Instance = new ProductService();
private static string connstr = ConfigurationManager.ConnectionStrings["SQLiteDB"].ConnectionString;

public DataTable GetData()
{
SQLiteConnection conn = null;
int num = 0;
int productNum = 10;
try
{
conn = new SQLiteConnection(connstr);
conn.Open();
string sql = "select * from users";
//SQLiteParameter[] parameter = { new SQLiteParameter("@product", product), new SQLiteParameter("@productNum", productNum) };
SQLiteCommand cmd = new SQLiteCommand(sql, conn);
//cmd.Parameters.AddRange(parameter);
SQLiteDataAdapter sda = new SQLiteDataAdapter(cmd);
DataTable dt = new DataTable();
sda.Fill(dt);

return dt;
}
catch (Exception ex)
{
return null;
}

}
}

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM