C Simple Query Method for SQLite Database
- 2021-10-24 23:28:49
- OfStack
This article illustrates a simple C # query for data in an SQLite database. Share it for your reference, as follows:
//sqlite Database driven component
using System.Data.SQLite;
// Insert database function
int SQLquery(string sql)
{
try
{
// Open the database
SQLiteConnection conn = new SQLiteConnection();
SQLiteConnectionStringBuilder connstr = new SQLiteConnectionStringBuilder();
connstr.DataSource = "my.db";
conn.ConnectionString = connstr.ToString();
conn.Open();
// Execute SQL Statement
SQLiteCommand cmd = new SQLiteCommand();
cmd.CommandText = sql;
cmd.Connection = conn;
SQLiteDataReader reader=cmd.ExecuteReader();
int result=0;
while (reader.Read())
{
result=1;
}
// Close all connections
connstr.Clear();
conn.Close();
return result;
}
catch (Exception ex)
{
//
}
return 0;
}
For more readers interested in C # related content, please check the topics on this site: "Summary of Thread Use Skills in C # Programming", "Summary of C # Operating Excel Skills", "Summary of XML File Operation Skills in C #", "C # Common Control Usage Tutorial", "WinForm Control Usage Tutorial", "C # Data Structure and Algorithm Tutorial", "C # Array Operation Skills Summary" and "C # Object-Oriented Programming Introduction Tutorial"
I hope this article is helpful to everyone's C # programming.