none
storing data in SQLite

    Question

  • Hello,

    I am complete noob in SQLite, and I would like to ask a question on how to store specific data in SQLite files.

    I've written some template code, but i dont seem to understand how exactly to implement what i want.

    Basically, i have a listbox with items, and 6 comboboxes that have numerical values and strings. I would like to store all this data in SQLite files so that I could later compare the results. 

    I would really appreciate if anyone could point out specifically how could I implement this in the following code :

    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;

    namespace WindowsFormsApplication1
    {
        public partial class Form1 : Form
        {
            private SQLiteConnection sql_con;
            private SQLiteCommand sql_cmd;
            private SQLiteDataAdapter DB;
            private DataSet DS = new DataSet();
            private DataTable DT = new DataTable();

            public Form1()
            {
                InitializeComponent();
            }

            private void SetConnection()
            {
              sql_con = new SQLiteConnection("Data Source=file1.db;Version=3;New=False;Compress=True;");
            }

            private void ExecuteQuery(string txtQuery)
            {
                SetConnection();
                sql_con.Open();
                sql_cmd = sql_con.CreateCommand();
                sql_cmd.CommandText = txtQuery;
                sql_cmd.ExecuteNonQuery();
                sql_con.Close();

            }

            private void button1_Click(object sender, EventArgs e)
            {
                SetConnection();
                sql_con.Open();
                sql_cmd = sql_con.CreateCommand();
                string CommandText = "copy from textbox";
                DB = new SQLiteDataAdapter(CommandText, sql_con);
                DS.Reset();
                DB.Fill(DS);
                DT = DS.Tables[0];
                Grid.DataSource = DT;
                sql_con.Close();
            }

        }
    }

     

    This code was taken as a template, so it might be very wrong. 

    Thanks a lot!

    Tuesday, June 19, 2012 12:09 PM

Answers

All replies

  • Hi, 

    Are you facing any error? 

    Here is the examples shown how to work with SQLLite and ADO.Net

    http://www.ivankristianto.com/software-development/visual-studio-net/howto-use-sqlite-ado-net-with-c/943/

    http://decoding.wordpress.com/2009/01/14/using-sqlite-with-net/

    Let us know if you face any issue. 


    If this post answers your question, please click "Mark As Answer". If this post is helpful please click "Mark as Helpful".



    • Edited by Kris444 Tuesday, June 19, 2012 2:19 PM
    Tuesday, June 19, 2012 2:17 PM
  • Hi Ivan

    Very nice tutorial on your web site. Unfortunately, I get this annoying compile error 

    Cannot implicitly convert type 'string' to 'System.Windows.Forms.DataGridViewTextBoxColumn' C:\Users\Nikotin\AppData\Local\Temporary Projects\WindowsFormsApplication1\Form1.Designer.cs

    and it points out to form1 code in Form1.Designer

    // Form1
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(468, 262);
                this.Controls.Add(this.dataGridView1);
                this.Name = "Form1"; <<<<<<<<<<<<<<<<<< error
                this.Text = "Form1";
                this.Load += new System.EventHandler(this.Form1_Load);
                ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit();
                this.ResumeLayout(false);

    Can you please point out what is the problem?

    Thank you!

    Tuesday, June 19, 2012 3:33 PM
  • Hi markis88 ,
    You have a Datagridview   which contains  a column named  “Name ” in your Form1 , am I right ?
    Please try to rename this columun  , and then  try to use “this.Name = "Form1";”again. I hope it is helpful to you .

    Check this link out to see some similar discussions :

    http://social.msdn.microsoft.com/Forums/zh/winformsdesigner/thread/5b26311e-efb2-42a8-9f36-18fe37c7dc64

    If you have any questions ,feel free to let me know .
    Regards,


    Lisa Zhu [MSFT]
    MSDN Community Support | Feedback to us


    Wednesday, June 20, 2012 5:29 AM
    Moderator