WPF automatically selects DLLs, as an example of SQLite

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.