Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
D

Dhjjf

@Dhjjf
About
Posts
1
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Ask C# everyone God, about SQLiteHelper increase delete to modify the static to directly call the way
    D Dhjjf

    The class I use in the project is a SQLite database that helps static classes. It can be called directly without using instantiation.
    Originally there are a lot of related classes on the Internet. After using a class, you can't call it.

    private void TextBox2_TextChanged(object sender, EventArgs e) //新增插入数据
    {
    SQLiteCommand cmdInsert = new SQLiteCommand(mConn);
    string sql = "INSERT INTO KD(postID,ddtime)values(@postID,@ddtime)";
    SQLiteParameter[] cmdParms = new SQLiteParameter[]{
    new SQLiteParameter("@postID", (textBox2.Text)),
    new SQLiteParameter("@ddtime", DateTime.Now)
    };
    cmd.ExecuteNonQuery(sql,cmdParms);
    }

    The SQLiteHelper class source is as follows

    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.Common;
    using System.Data.SQLite;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows.Forms;

    namespace SQLiteQueryBrowser
    {
    /// /// 本类为SQLite数据库帮助静态类,使用时只需直接调用即可,无需实例化
    ///
    public static class SQLiteHelper
    {
    /// /// 数据库连接字符串
    ///
    //public static string connectionString = "Data Source=" + Application.StartupPath + "\\" + System.Configuration.ConfigurationSettings.AppSettings["Contr"];
    public static string connectionString = "Data Source=" + Application.StartupPath + "/KDDB.db";

        #region 执行数据库操作(新增、更新或删除),返回影响行数
        /// /// 执行数据库操作(新增、更新或删除)
        /// 
        /// SqlCommand对象
        /// 所受影响的行数
        public static int ExecuteNonQuery(SQLiteCommand cmd)
        {
            int result = 0;
            if (connectionString == null || connectionString.Length == 0)
                throw new ArgumentNullException("connectionString");
            using (SQLiteConnection con = new SQLiteConnection(connectionString))
            {
                SQLiteTransaction trans = null;
                PrepareCommand(cmd, con, ref trans, true, cmd.CommandType, cmd.CommandText);
                try
                {
                    result = cmd.ExecuteNonQuery();
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw ex;
                }
            }
    
    C# database csharp sqlite linq workspace
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups