In the process of learning SQLite, it was found that the DLL is 32-bit and 64-bit, initially felt very annoyed, but carefully looked under,
It is not a very troublesome thing to find the program to choose the DLL itself, as follows:
1> Creating a SQLite data
2> Create a project
3> Create a new class
1 classentrance:application2 {3 [STAThread]4 Static voidMain ()5 {6 stringDll32 =@". \sqlitedll\system.data.sqlite32.dll";7 stringDll64 =@". \sqlitedll\system.data.sqlite64.dll";8 stringDllPath =@". \system.data.sqlite.dll";9 Ten if(Intptr.size = =8) One { A using(FileStream fs=file.create (DllPath)) {} -File.Copy (Dll64,dllpath,true); - } the Else if(Intptr.size = =4) - { - using(FileStream fs=file.create (DllPath)) {} -File.Copy (Dll32,dllpath,true); + } - Else +{MessageBox.Show ("error!");} A //start up the main window atApplication app =Newapplication (); -MainWindow window =NewMainWindow (); - app. Run (window); - } -}
4> Add button Response events
1 Private voidButton_Click (Objectsender, RoutedEventArgs e)2 {3 stringstrconn =@"Data source=.\student.db; Version=3";4 stringStrcmd ="select * from Stu";5Sqliteconnection con =Newsqliteconnection (strconn);6 Try7 {8 con. Open ();9 }Ten Catch(Exception ex) One {MessageBox.Show (ex. ToString ()); } A - -Sqlitecommand cmd =NewSqlitecommand (Strcmd, con); the - - cmd. ExecuteNonQuery (); - +Sqlitedataadapter Dataapp =Newsqlitedataadapter (cmd); -DataTable dt =NewDataTable ("a"); + dataapp.fill (DT); AdataGrid1.ItemsSource =dt. DefaultView; at dataapp.update (DT); - con. Close (); - } -}
5> Final effect (WIN8 64-bit test effect on the left, XP 32-bit test effect on the right) [Note: The new version of System.Data.SQLite.dll may require msvcr100.dll support in the test
On the machine if not the DLL will be inexplicably crash, but also catch the exception, it may be related to the version, you can use depends to see the]
WPF automatically selects DLLs, as an example of SQLite