How to reuse SqlCommand parameter through every iteration?

前端 未结 4 1935
暖寄归人
暖寄归人 2020-12-31 01:41

I want to implement a simple delete button for my database. The event method looks something like this:

private void btnDeleteUser_Click(object sender, Event         


        
4条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-31 02:36

    I would use this:

    public static class DbExtensions
    {
        public static void AddParameter(SQLiteCommand command, string name, DbType type, object value)
        {
            var param = new SQLiteParameter(name, type);
            param.Value = value;
            command.Parameters.Add(param);
        }
    }
    

    Then, call this:

    DbExtensions.AddParameter(command, "@" + fieldOfSearch[i], DbType.String, value[i]);
    

提交回复
热议问题