using System;
Using System. Data. SQLite;
Using System. Windows. Forms;
The namespace WindowsFormsApp4
{
Public partial class Form1: Form
{
Public _click ()
{
InitializeComponent ();
}
Private void button1_Click (object sender, EventArgs e)
{
Sqlite sqlite=new sqlite (" devices ", "dev");
}
}
The class sqlite
{
//global variable
SQLiteConnection m_dbConnection;
//the constructor
Public sqlite (string db_name, string table_name)
{
CreateNewDatabase (db_name);
ConnectToDatabase (db_name);
//a table and create fields: name varchar (20), the model varchar (20), sn varchar (20)
CreateTable (table_name);
//insert the data (name, model, sn)
Insert (table_name, "millet", "3 m", "sn123456");
//query data
Select (table_name);
}
//create the database
Void createNewDatabase (string db_name)
{
SQLiteConnection. CreateFile (${db_name}. Sqlite ");
}
//create a connection to the specified database
Void connectToDatabase (string db_name)
{
M_dbConnection=new SQLiteConnection ($" Data Source={db_name}. Sqlite; Version=3;" );
M_dbConnection. The Open ();
}
//create a table in the specified database
Void createTable (string table_name)
{
String SQL=$" create table {table_name} (name varchar (20), the model varchar (20), sn varchar (20)) ";
SQLiteCommand command=new SQLiteCommand (SQL, m_dbConnection);
The command. ExecuteNonQuery ();
}
//insert some data
Void insert (string table_name, string name, string model, a string of sn)
{
String SQL=$" insert into {table_name} (name, model, sn) values (' {name} ', '{model}', '{sn}') ";
SQLiteCommand command=new SQLiteCommand (SQL, m_dbConnection);
The command. ExecuteNonQuery ();
}
//using SQL query and display the results
Void the Select (string table_name)
{
String SQL=$" select * from {table_name} ";
SQLiteCommand command=new SQLiteCommand (SQL, m_dbConnection);
SQLiteDataReader reader=command. ExecuteReader ();
While (reader. The Read ())
MessageBox. Show (
"\ tname:" + reader/" name "+
"\ tmodel:" + reader [" model "] +
"\ passes:" + reader (" sn "));
}
}
}
More than this in a temporary new project alone, fully functional normal
//===========================================================================
I put the code above the whole copy to another project is wrong, I can't find the problem, for a great god
CodePudding user response:
Two projects are installed inside the PM SQLite:Install - package system. Data. Sqlite. X64
CodePudding user response:
Check the Environment. Is64BitProcess this lookCodePudding user response: