当前位置: 首页>>代码示例>>C#>>正文


C# SQLite.SQLiteParameter类代码示例

本文整理汇总了C#中System.Data.SQLite.SQLiteParameter的典型用法代码示例。如果您正苦于以下问题:C# SQLiteParameter类的具体用法?C# SQLiteParameter怎么用?C# SQLiteParameter使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SQLiteParameter类属于System.Data.SQLite命名空间,在下文中一共展示了SQLiteParameter类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: AddRili

        public int AddRili(Rili rili)
        {
            int result = 0;
            try
            {
                string sql = "INSERT INTO t_rili(Yangli,Nongli,Zhigan,Xingzuo,Xingqi,Yi,Ji)values(@Yangli,@Nongli,@Zhigan,@Xingzuo,@Xingqi,@Yi,@Ji)";

                SQLiteParameter[] parameters = new SQLiteParameter[]{
                                         new SQLiteParameter("@Yangli",rili.Yangli),
                                         new SQLiteParameter("@Nongli",rili.Nongli),
                                         new SQLiteParameter("@Zhigan",rili.Zhigan),
                                         new SQLiteParameter("@Xingzuo",rili.Xingzuo),
                                         new SQLiteParameter("@Xingqi",rili.Xingqi),
                                         new SQLiteParameter("@Yi",rili.Yi),
                                         new SQLiteParameter("@Ji",rili.Ji)
                                         };
                SqlAction action = new SqlAction();
                result = action.IntQuery(sql, parameters);
            }
            catch (Exception ex)
            {
                Log.Error("插入日历数据出错:" + ex.ToString());
            }
            return result;
        }
开发者ID:JimmyFung,项目名称:DesktopHelper,代码行数:25,代码来源:DataManipulation.cs

示例2: ExecuteNonQuery

 /// <summary> 
 /// 对SQLite数据库执行增删改操作,返回受影响的行数。 
 /// </summary> 
 /// <param name="sql">要执行的增删改的SQL语句</param> 
 /// <param name="parameters">执行增删改语句所需要的参数,参数必须以它们在SQL语句中的顺序为准</param> 
 /// <returns></returns> 
 public int ExecuteNonQuery(string sql, SQLiteParameter[] parameters)
 {
     int affectedRows = 0;
     try
     {
         using (SQLiteConnection connection = new SQLiteConnection(connectionString))
         {
             connection.Open();
             using (DbTransaction transaction = connection.BeginTransaction())
             {
                 using (SQLiteCommand command = new SQLiteCommand(connection))
                 {
                     command.CommandText = sql;
                     if (parameters != null)
                     {
                         command.Parameters.AddRange(parameters);
                     }
                     affectedRows = command.ExecuteNonQuery();
                 }
                 transaction.Commit();
             }
         }
     }
     catch
     { }
     return affectedRows;
 }
开发者ID:JimmyFung,项目名称:DesktopHelper,代码行数:33,代码来源:UpdateDBHelper.cs

示例3: GetUsers

        public List<UserEntity> GetUsers(int skip, int pagesize, string userName, out int count)
        {
            StringBuilder sql = new StringBuilder();
            sql.Append(" select Uid,Name,Photo,RolesIds,Status from t_users ");

            if (!string.IsNullOrEmpty(userName))
            {
                sql.Append(" where Uid like @Uid ");
            }
            if (pagesize != 0)
            {
                sql.Append(" Limit @count Offset @skip ");

            }


            SQLiteParameter[] para = new SQLiteParameter[] {
                new SQLiteParameter("@count", pagesize),
                new SQLiteParameter("@skip", skip),
                new SQLiteParameter("@Uid", "%"+userName+"%")
            };
            SqlLiteHelper sqliteHelper = new SqlLiteHelper();
            DataTable dataTable = sqliteHelper.GetDataTable(sql.ToString(), para);
            List<UserEntity> userEntities = new List<UserEntity>();
            foreach (DataRow dataRow in dataTable.Rows)
            {
                userEntities.Add(Conver2Entity(dataRow));
            }
            count = sqliteHelper.GetCount("t_users");
            return userEntities;
        }
开发者ID:PerryPal,项目名称:Huber.net,代码行数:31,代码来源:UserDal.cs

示例4: Main

        static void Main(string[] args)
        {
            // On crée nos variables:
            SQLiteConnection connection = new SQLiteConnection();
            
            // Disponible sur le site http://www.connectionstrings.com
            // "Data Source=filename;Version=3;"        
            connection.ConnectionString = "Data Source=test.db;Version=3";
            // Il serait bien sûr possible d'en faire plus, par exemple, mot de passe, mais on va s'en tenir à ça.

            // Ouvre la connexion à la base de donnée
            connection.Open();


            // À présent, il faut se rappeler le SQL que nous avons appris pendant les cours de base de donneés:
            // Créons donc nos tables:

            SQLiteCommand command = new SQLiteCommand("DROP TABLE IF EXISTS Étudiants; CREATE TABLE Étudiants(" +
                " ID integer Primary Key, " +
                " Nom string, " +
                " Prenom string, " +
                " DateDeNaissance date, " +
                " Ville string, " +
                " Technique string, " +
                " NuméroTéléphone string); ");

            command.Connection = connection;
            command.ExecuteNonQuery();

            // Il est possible de faire nos opérations en plus qu'une étape:

            SQLiteCommand command2 = new SQLiteCommand("INSERT INTO Étudiants VALUES ( @ID, @Nom, @Prenom, @DateNaissance, @Ville, @Technique,@No);", connection);
            command2.Parameters.AddWithValue("@ID", null);
            command2.Parameters.AddWithValue("@Nom", "Di Croci");

            SQLiteParameter param3 = new SQLiteParameter("@Prenom");
            param3.Value = "Michel";
            command2.Parameters.Add(param3);

            command2.Parameters.AddWithValue("@DateNaissance", "13/10/1979");
            command2.Parameters.AddWithValue("@Ville", "L'Assomption");
            command2.Parameters.AddWithValue("@Technique", "Informatique");
            command2.Parameters.AddWithValue("@No", "haha!");

            command2.ExecuteNonQuery();

            // Comme vous le constatez, on ne sait pas quel numéro d'enregistrement vient d'être entré...
            // Dans le cas de l'utilisation de clé étrangère (comme dnas notre TP), il peut devenir pratique d'avoir ce numéro
            // dans ce cas, nous devons utiliser select last_insert_rowid

            command.CommandText = "SELECT last_insert_rowid() FROM Étudiants";
            // Comme vous le savez, SELECT nous retourne un élément contrairement à un INSERT ou un UPDATE OU UN DELETE
            // Cela siginifie entre autre que la requête précédente va nous retourner qu'un seul scalaire, sinon nous aurions
            // utilisé le SQLiteDataReader que nous verrons ultérieurement
            object id = command.ExecuteScalar();

            Console.WriteLine(id);

            connection.Close();
        }
开发者ID:drynish,项目名称:ecole,代码行数:60,代码来源:Program.cs

示例5: Login

        public static bool Login(int accountId, string password)
        {
            using (SQLiteConnection con = new SQLiteConnection(Settings.Default.AccountingConnectionString))
            {
                using (SQLiteCommand cmd = new SQLiteCommand())
                {
                    cmd.Connection = con;
                    cmd.CommandText = "SELECT COUNT(accountId) FROM vAccountPassword WHERE accountId = @account AND password = @password";
                    SQLiteParameter pAccount = new SQLiteParameter("account",accountId);
                    pAccount.Direction = ParameterDirection.Input;

                    SQLiteParameter pPassword = new SQLiteParameter("password", password);
                    pPassword.Direction = ParameterDirection.Input;

                    cmd.Parameters.AddRange(new SQLiteParameter[] { pAccount, pPassword });
                    con.Open();
                    if (Convert.ToInt32(cmd.ExecuteScalar()) == 1)
                    {
                        con.Close();
                        return true;
                    }
                    con.Close();
                    return false;
                }
            }
        }
开发者ID:ahtisam,项目名称:HomeAccounting,代码行数:26,代码来源:LoginChecker.cs

示例6: AddPatientBaseInfo

 public long AddPatientBaseInfo(PatientInfo model)
 {
     StringBuilder stringBuilder = new StringBuilder();
     stringBuilder.Append("insert into PatientBaseInfo(");
     stringBuilder.Append("PatientAge,PatientName,PatientSex,BeHospitalizedDate,Bed,CourtyardState,LeaveHospitalDate,LeaveHospitalAgent,Diacrisis)");
     stringBuilder.Append(" values (");
     stringBuilder.Append("@PatientAge,@PatientName,@PatientSex,@BeHospitalizedDate,@Bed,@CourtyardState,@LeaveHospitalDate,@LeaveHospitalAgent,@Diacrisis)");
     stringBuilder.Append(";select LAST_INSERT_ROWID()");
     SQLiteParameter[] array = new SQLiteParameter[]
     {
         new SQLiteParameter("@PatientAge", DbType.Int16),
         new SQLiteParameter("@PatientName", DbType.String),
         new SQLiteParameter("@PatientSex", DbType.String),
         new SQLiteParameter("@BeHospitalizedDate", DbType.Date),
         new SQLiteParameter("@Bed", DbType.String),
         new SQLiteParameter("@CourtyardState", DbType.String),
         new SQLiteParameter("@LeaveHospitalDate", DbType.Date),
         new SQLiteParameter("@LeaveHospitalAgent", DbType.String),
         new SQLiteParameter("@Diacrisis", DbType.String)
     };
     array[0].Value = model.Age;
     array[1].Value = model.Name;
     array[2].Value = model.Sex;
     array[3].Value = model.BeHospitalizedDate;
     array[4].Value = model.Bed;
     array[5].Value = model.CourtyardState;
     array[6].Value = model.LeaveHospitalDate;
     array[7].Value = model.LeaveHospitalAgent;
     array[8].Value = model.Diacrisis;
     object single = DbHelperSQLite.GetSingle(stringBuilder.ToString(), array);
     return Convert.ToInt64(single);
 }
开发者ID:jibie,项目名称:CaseHistory,代码行数:32,代码来源:DataEngine.cs

示例7: ExecuteDataTable

        /// <summary> 
        /// 执行一个查询语句,返回一个包含查询结果的DataTable 
        /// </summary> 
        /// <param name="sql">要执行的查询语句</param> 
        /// <param name="parameters">执行SQL查询语句所需要的参数,参数必须以它们在SQL语句中的顺序为准</param> 
        /// <returns></returns> 
        public int ExecuteDataTable(StringBuilder sql, SQLiteParameter[] parameters, ref DataTable dt)
        {
            try
            {
                using (SQLiteConnection connection = new SQLiteConnection(connectionString))
                {
                    connection.Open();
                    using (SQLiteCommand command = new SQLiteCommand(sql.ToString(), connection))
                    {
                        if (parameters != null)
                        {
                            command.Parameters.AddRange(parameters);
                        }

                        SQLiteDataAdapter adapter = new SQLiteDataAdapter(command);
                        adapter.Fill(dt);
                        return 0;
                    }
                }

            }
            catch (Exception ex)
            {
                return -1;
                throw new Exception(ex.Message);
            }
        }
开发者ID:hanxinlei2002,项目名称:LotteryApp,代码行数:33,代码来源:SQLiteDBHelper.cs

示例8: addUser

        // add users to the database
        public bool addUser(string username, string password)
        {
            SQLiteCommand dbcmd = dbcon.CreateCommand();
            string Sql = "INSERT INTO users VALUES (?,?); INSERT INTO scores VALUES (?,?);";
            dbcmd.CommandText = Sql;
            SQLiteParameter param1 = new SQLiteParameter();
            SQLiteParameter param2 = new SQLiteParameter();
            SQLiteParameter param3 = new SQLiteParameter();
            SQLiteParameter param4 = new SQLiteParameter();
            param1.Value = username;
            param2.Value = password;
            param3.Value = username;
            param4.Value = 0;
            dbcmd.Parameters.Add(param1);
            dbcmd.Parameters.Add(param2);
            dbcmd.Parameters.Add(param3);
            dbcmd.Parameters.Add(param4);
            SQLiteDataReader reader = dbcmd.ExecuteReader();

            reader.Close();
            reader = null;
            // dispose of database commands
            dbcmd.Dispose();
            dbcmd = null;

            // should only be called if conditions are right
            // for adding users; always return true
            return true;
        }
开发者ID:jsdodgers,项目名称:ICS168Swarch,代码行数:30,代码来源:SQLiteDB.cs

示例9: AddLoginHistory

 /// <summary>
 /// 添加登录记录
 /// </summary>
 /// <param name="userid"></param>
 /// <returns></returns>
 public static bool AddLoginHistory(Int64 userid)
 {
     string sqlStr = "INSERT INTO LoginHistory(UserID,LoginTime) Values(@USERID,datetime('now','localtime'));";
     SQLiteParameter parameter = new SQLiteParameter("@USERID", System.Data.DbType.Int64);
     parameter.Value = userid;
     return ExecuteNonQuery(sqlStr, parameter) > 0;
 }
开发者ID:kcly3027,项目名称:freePhoto,代码行数:12,代码来源:UserDAL.cs

示例10: data

        public void data()
        {
            p1 = new SQLiteParameter("@person_id", DbType.Int32);
            p2 = new SQLiteParameter("@day", DbType.Int32);
            p3 = new SQLiteParameter("@month_id", DbType.Int32);
            p4 = new SQLiteParameter("@usage", DbType.Int32);
               // SQLiteParameter p4 = new SQLiteParameter("@w_usage", DbType.Int32);

            DataDao.sqlite_cmd.Parameters.Add(p1);
            DataDao.sqlite_cmd.Parameters.Add(p2);
            DataDao.sqlite_cmd.Parameters.Add(p3);
            DataDao.sqlite_cmd.Parameters.Add(p4);

            //for (person_id = 1; person_id <= 10000; person_id++)
            for (person_id = 1; person_id <= 10; person_id++)
            {
               // for (month_id = 1; month_id <= 24; month_id++)
                 for (month_id = 1; month_id <= 12; month_id++)
                {
                    for (day = 1; day <= 30; day++)
                    // for (day = 1; day <= 10; day++)
                    {
                        int usage = rnd.Next(1, 12);
                        p1.Value = person_id;
                        p2.Value = day;
                        p3.Value = month_id;
                        p4.Value = usage;
                        DataDao.sqlite_cmd.ExecuteNonQuery();

                    }
                }

            }
        }
开发者ID:vivekmurli,项目名称:customerinfo,代码行数:34,代码来源:InsertQuery.cs

示例11: insertCity

        public void insertCity()
        {
            try
            {
                //DataDao.sqlite_cmd = sqlite_conn.CreateCommand();
                DataDao.sqlite_cmd.CommandText = "insert into city(city_id,city_name,state) values (@city_id,@city_name,@state)";
                p1 = new SQLiteParameter("@city_id", DbType.Int32);
                p2 = new SQLiteParameter("@city_name", DbType.String);
                p3 = new SQLiteParameter("@state", DbType.String);

                DataDao.sqlite_cmd.Parameters.Add(p1);
                DataDao.sqlite_cmd.Parameters.Add(p2);
                DataDao.sqlite_cmd.Parameters.Add(p3);

                for (int m = 1; m <= 3; m++)
                {
                   // for (int n = m; n <= m-1; n++)
                   // {
                       p1.Value = m;
                       p2.Value = city_name[m-1];
                       p3.Value = state[0];
                       DataDao.sqlite_cmd.ExecuteNonQuery();
                   // }

                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("SQLite Exception : {0}", ex.Message);

            }
        }
开发者ID:vivekmurli,项目名称:customerinfo,代码行数:32,代码来源:InsertQuery.cs

示例12: SelectArray

        public static List<Object[]> SelectArray( IDbTransaction transaction, string statement, IEnumerable<object> parameters )
        {
            List<Object[]> rows = null;
            using ( IDbCommand Command = new SQLiteCommand() ) {
                Command.Connection = transaction.Connection;
                Command.CommandText = statement;
                foreach ( object p in parameters ) {
                    SQLiteParameter sqp = new SQLiteParameter();
                    sqp.Value = p;
                    Command.Parameters.Add( sqp );
                }

                IDataReader rd = Command.ExecuteReader();

                rows = new List<object[]>();
                if ( rd.Read() ) {
                    Object[] fields = new Object[rd.FieldCount];
                    do {
                        for ( int i = 0; i < rd.FieldCount; ++i ) {
                            try {
                                fields[i] = rd.GetValue( i );
                            } catch ( OverflowException ) {
                                // workaround, GetValue() and GetValues() try to incorrectly cast a signed tinyint to an unsigned byte
                                fields[i] = rd.GetInt32( i );
                            }
                        }
                        rows.Add( fields );
                        fields = new Object[rd.FieldCount];
                    } while ( rd.Read() );
                }
            }
            return rows;
        }
开发者ID:AdmiralCurtiss,项目名称:HyoutaTools,代码行数:33,代码来源:SqliteUtil.cs

示例13: ExecuteNonQuery

        public static int ExecuteNonQuery(string sql, SQLiteParameter[] parameters = null, string connectionString = "")
        {
            if (string.IsNullOrEmpty(connectionString))
                connectionString = ConnectionString;

            int affectedRows;
            using (var connection = new SQLiteConnection(connectionString))
            {
                connection.Open();
                using (var transaction = connection.BeginTransaction())
                {
                    using (var command = new SQLiteCommand(connection))
                    {
                        command.CommandText = sql;
                        if (parameters != null)
                        {
                            command.Parameters.AddRange(parameters);
                        }
                        affectedRows = command.ExecuteNonQuery();
                    }
                    transaction.Commit();
                }
            }
            return affectedRows;
        }
开发者ID:atwayne,项目名称:guesswhat_wordservice,代码行数:25,代码来源:SQLiteHelper.cs

示例14: RemoveConnections

		public void RemoveConnections(Int64 parentQueryId)
		{
			const string parentQueryIdParamName = "@parentQueryId";
			string       strSQLClause           = null;

			if (!this.ReadOnly)
			{
				using (this.Connection.OpenWrapper())
				{
					var deleteCommand = new RowDeleteCommand(this.Connection, this.TableDefinition);

					strSQLClause = string.Format(
						"[{0}] = {1}",
						ParentQueryIdFn,
						parentQueryIdParamName
					);

					var parentQueryIdParam = new SQLiteParameter(parentQueryIdParamName, DbType.Int64)
					{
						Value = parentQueryId
					};

					var parameters = new List<SQLiteParameter> { parentQueryIdParam };

					deleteCommand.SetCommandConstraints(strSQLClause, parameters);

					deleteCommand.Execute(100);
				}
			}
		}
开发者ID:saycale,项目名称:MSSQLServerAuditor,代码行数:30,代码来源:DynamicConnectionDirectory.cs

示例15: GetRecord

 public static int GetRecord(string name)
 {
     string sql = "select rank from Demo where [email protected]";
     SQLiteDBHelper db = new SQLiteDBHelper(dbPath);
     SQLiteParameter[] parameters = new SQLiteParameter[] { new SQLiteParameter("@name", SqliteEscape(name)) };
     return int.Parse(db.ExecuteScalar(sql, parameters).ToString());
 }
开发者ID:yuyuzeze,项目名称:Site,代码行数:7,代码来源:DBUitility.cs


注:本文中的System.Data.SQLite.SQLiteParameter类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。