Click here to Skip to main content
15,878,970 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SQLite;
using System.Data.SqlClient;

using System.IO;
namespace sqlitesample
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
           
        }



        private void Form1_Load(object sender, EventArgs e)
        {

        }

        private void insertconnect_Click(object sender, EventArgs e)
        {
            // [snip] - As C# is purely object-oriented the following lines must be put into a class:

            // We use these three SQLite objects:
            SQLiteConnection sqlite_conn;
            SQLiteCommand sqlite_cmd;
            SQLiteDataReader sqlite_datareader;

            // create a new database connection:
            sqlite_conn = new SQLiteConnection("Data Source=dbDemo.db;Version=3;New=True;Compress=True;");

            // open the connection:
            sqlite_conn.Open();

            // create a new SQL command:
            sqlite_cmd = sqlite_conn.CreateCommand();
 
        }
    }
}


by click button after that it gets like this ===

error

Could not load file or assembly 'System.Data.SQLite, Version=1.0.94.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139' or one of its dependencies. An attempt was made to load a program with an incorrect format.
Posted
Updated 17-Sep-14 4:28am
v2
Comments
Bernhard Hiller 18-Sep-14 2:56am    
You copied your snippet from http://adodotnetsqlite.sourceforge.net/documentation/csharp_example.php but fail to understand it. Work thru it, try to understand hwat it does!

1 solution

The error is ovbious, you're not having the System.Data.SQLite.dll saved inside your library folder (bin).

You should make sure that you're having this library file (.dll) inside the binary folder. So that you can use it. Make sure read/write permissions are allowed and also, that you're calling the exact name of the file.
 
Share this answer
 
Comments
harshavardhan12345678 17-Sep-14 23:36pm    
now the error is Unable to open the database
harshavardhan12345678 18-Sep-14 1:44am    
error in this

private void insertconnect_Click(object sender, EventArgs e)
{
// [snip] - As C# is purely object-oriented the following lines must be put into a class:

// We use these three SQLite objects:
SQLiteConnection sqlite_conn;
SQLiteCommand sqlite_cmd;
SQLiteDataReader sqlite_datareader;



sqlite_conn = new SQLiteConnection(); // Create an instance of the object
sqlite_conn.ConnectionString = "Data Source=c:\\eminosoft.db;Version=3;New=True;Compress=True;"; // Set the ConnectionString
sqlite_conn.Open(); // Open the connection. Now you can fire SQL-Queries

// create a new SQL command:
sqlite_cmd = sqlite_conn.CreateCommand();

}
Bernhard Hiller 18-Sep-14 2:51am    
Oh dear... Did you place the database file to Data Source=c:\\eminosoft.db on the target computer? By the way, that is a very very bad place for a database file. SQLite database files are often stored in the user profile; c:\programdata\YourCompany\YourApplication\YourDatabaseFile.db can be an appropriate alternative.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900