在命令执行mysql数据插入期间遇到致命错误

时间:2017-02-26 13:00:40

标签: c# mysql

我收到命令执行期间遇到的"致命错误"运行这部分代码时出现错误消息:

private void button1_Click(object sender, EventArgs e)
    {
        MySqlCommand cmd = new MySqlCommand("INSERT INTO clienti(nume, prenume, localitate, cnp, adresa, telefon, email) VALUES(@numen, @prenumep, @locl, @cnpc, @adresaa, @telefont, @emaile); ", conn);

        try
        {
            if (numen.Text.Length > 0 && prenumep.Text.Length > 0 && locl.Text.Length > 0 && adresaa.Text.Length > 0 && telefont.Text.Length > 0 && emaile.Text.Length > 0)
            {
                cmd.Parameters.AddWithValue("@numen", numen.Text);
                cmd.Parameters.AddWithValue("@prenumep", prenumep.Text);
                cmd.Parameters.AddWithValue("@locl", locl.Text);
                cmd.Parameters.AddWithValue("@adresaa", adresaa.Text);
                cmd.Parameters.AddWithValue("@telefont", telefont.Text);
                cmd.Parameters.AddWithValue("@emaile", emaile.Text);
                cmd.ExecuteNonQuery();
            }
            else
                throw new Exception("Completati toate informatiile");
            MessageBox.Show("Clientul " + numen.Text + " a fost adaugat");
            numen.Text = "";
            prenumep.Text = "";
            locl.Text = "";
            adresaa.Text = "";
            telefont.Text = "";
            emaile.Text = "";

        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
    }

信息从一些文本框中提取,必须写入MySQL数据库。

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

您没有为import collections import itertools def selection(a, b, c, d): """program has 4 main parts, firstly, triple_sum finds possible 3sums in the list abc secondly, is_iterable ensures that inputs of tuple length 1 (ie. not iterable) are made iterable thirdly, main function determines if there exists possible a, b, c in abc that correspond to each d fourthly, main function checks if only 1 of the 3 integers from triple_sum exist in each array""" '''use sort O(n log n) to sort input array, then find possible 3sums in O(n^2)''' def triple_sum(a, res): a.sort() positions = collections.defaultdict(set) for i, n in enumerate(a): positions[n].add(i) for (i, ai), (j, aj) in itertools.combinations(enumerate(a), 2): n = res - ai - aj if positions[n].difference((i, j)): return n, ai, aj '''Ensure that all inputs are iterable''' def is_iterable(x): if isinstance(x, collections.Iterable): return x else: return x, a, b, c, d = is_iterable(a), is_iterable(b), is_iterable(c), is_iterable(d) abc = a + b + c abc = [i for i in abc] '''find value of d which has corresponding a, b, c and returns appropriate value if conditions are met''' ans_a, ans_b, ans_c, ans_d = 0, 0, 0, 0 for i in d: x = 0 - i j = triple_sum(abc, x) if j[0] in a and j[1] in b and j[2] in c: ans_a, ans_b, ans_c, ans_d = j[0], j[1], j[2], i break elif j[0] in a and j[2] in b and j[1] in c: ans_a, ans_b, ans_c, ans_d = j[0], j[2], j[1], i break elif j[1] in a and j[0] in b and j[2] in c: ans_a, ans_b, ans_c, ans_d = j[1], j[0], j[2], i break elif j[1] in a and j[2] in b and j[0] in c: ans_a, ans_b, ans_c, ans_d = j[1], j[2], j[0], i break elif j[2] in a and j[0] in b and j[1] in c: ans_a, ans_b, ans_c, ans_d = j[2], j[0], j[1], i break elif j[2] in a and j[1] in b and j[0] in c: ans_a, ans_b, ans_c, ans_d = j[2], j[1], j[0], i break else: continue return ans_a, ans_b, ans_c, ans_d 参数赋值,因此准备好的语句的执行失败。