C#在不使用checklistbox的情况下在mysql中插入复选框的值

时间:2017-01-01 10:19:42

标签: c# mysql

我在C#中使用MetroFramework,它没有Checklistbox。有人可以帮我解决如何在不使用checklistbox的情况下在mysql中插入复选框的值吗?

这是我搜索过的代码示例,但它无效。

(defconst dempron
  '("hic" "haec" "hoc" "huius" "huic" "hunc" "hanc" "hac" "hi" "hae" "horum"
    "harum" "his" "hos" "has"))

(defun dempron-search ()
  "A function to naively search for sentences in XML <p> tags
containing words from `dempron'. Run this in the buffer you want
to search, and it will search from POINT onwards, writing results
to a buffer called 'results'."
  (interactive)
  (beginning-of-line)

  (while (not (eobp)) ;; while we're not at the end of the buffer
    (let ((cur-line   ;; get the current line as a string
           (buffer-substring-no-properties
            (progn (beginning-of-line) (point))
            (progn (end-of-line) (point)))))

      ;; See if our current line is in a <p> tag (and run `string-match' so we
      ;; can extract the sentence with `match-string')
      (if (string-match "^<p>\\(.*\\)</p>$" cur-line)
      (progn
        ;; then extract the actual sentence with `match-string'
        (setq cur-line (match-string 1 cur-line))

        ;; For each word in our sentence... (split on whitespace and
        ;; anything the sentence is likely to end with)
        (dolist (word (split-string cur-line "[[:space:].?!\"]+"))
          ;; `downcase' to make our search case-insensitive
          (if (member (downcase word) dempron)
              ;; We have a match! Temporarily switch to the
              ;; results buffer and write the sentence
              (with-current-buffer (get-buffer-create "results")
                (insert cur-line "\n")))))))
    (forward-line 1))) ;; Move to the next line

这是我插入新数据的所有代码,它正在运行。但是我被困在&#34; @ morRI&#34;因为它有很多需要保存的复选框。上面的代码只是一些网站上的副本。

CheckBox[] checkboxes = new CheckBox[] { newRIadhd, newRIallergy, newRIanemia, newRIasthma, newRIautism, newRIdepression, newRIdownSyndrome, newRIdyscalculia, newRIDyslexia, newRIepilepsy, newRIheartFailure, newRIhypertension, newRIintDis, newRImigraine, newRIspinaBifida};

            List<string> checked = new List<string>();
foreach (Checkbox checkbox in checkboxes) {
  if (checkbox.Checked) {
    checked.Add(checkbox.Text);
  }
}
string checkedText = String.Join(", ", checked);

1 个答案:

答案 0 :(得分:0)

您似乎在插入数据时遇到了一些错误。看到 MySQL Insert into multiple tables? (Database normalization?)

上面的示例代码在checkedText的复选框中为每个选中的复选框指定逗号分隔的字符串(Text-property)。如果未选中任何复选框,则checkedText为空字符串。

要将字符串写入数据库,必须将其分配给相应的mysql参数(@mor_RI)并完成最后一个insert语句(带参数赋值)。

cmd.Parameters.AddWithValue("@mor_RI", checkedText);