Home > Net >  I have already melt, couldn't find the problem and solution
I have already melt, couldn't find the problem and solution

Time:01-07

 
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 look

CodePudding user response:

reference 1/f, I and my code Dui response:
two projects are installed inside the PM SQLite:
Install - package system. Data. Sqlite. X64


Installation is x64, the project also to x64

CodePudding user response:

refer to the second floor wanghui0380 response:
check Environment. Is64BitProcess this see

This is from where to check? Beginners are less likely to be...

CodePudding user response:

Can be run by default the DLL is not copied to the directory, try to manually copy the past,

CodePudding user response:

Sqlite requires two DLLS, x64 and x86

CodePudding user response:

How much is the DLL version?
"Data Source={db_name}. Sqlite; Version=3 ;"

CodePudding user response:

reference 3 floor really small white ah response:
Quote: reference 1/f, I and my code Dui response:
two projects are installed inside the PM SQLite:
Install - package system. Data. Sqlite. X64


Installation is x64, the project also to x64

The project itself is X64

CodePudding user response:

references on 7th floor is wrath of god reply:
DLL version is how much?
"Data Source={db_name}. Sqlite; Version=3 ;"

I deleted this sentence

CodePudding user response:

refer to 6th floor puzzle bobble response:
sqlite need two DLLS, x64 and x86

, this is a little difference between the two projects are PM installation, then the normal using references, the only difference really is the project can really have this two files, can't use this project without this two files, I tried to copy, the results still can not run

CodePudding user response:

References in the SQLite in the.net class library is to distinguish the x64 and x86, is such a place in my project:


If the project is compiled to AnyCPU, need to figure out whether the current environment when project start a 64 - bit system, if it is, you need to x64 DLL copied to the directory,
  •  Tags:  
  • C#
  • Related