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;
}

}
}

 

posted @ 2019-01-18 16:28  阳光下的行者  阅读(1373)  评论(0编辑  收藏  举报