【问题标题】:Cannot insert into oracle using .net (ORA 00911 error)无法使用 .net 插入到 oracle(ORA 00911 错误)
【发布时间】:2014-07-19 20:47:19
【问题描述】:

所以,我正在使用 .NET 和 oracle 11g express 构建一个 C# 应用程序。我已经连接到数据库,但是由于某种原因,它无法插入到数据库中,它一直给出 ORA 00911 错误。这是代码:

    private void toolStripButton1_Click(object sender, EventArgs e)
    {
        string salvar;           
        dbConnection conn = new dbConnection();
        try
        {
            conn.tryconection();
            salvar = "INSERT INTO Client(Name, Document, City, Contact, Addr, District, Zipcode, Phone_1, Phone_2, Cel_1, Cel_2, eymael, tobar) VALUES('" + boxNome.Text + "', '" + boxDocumento.Text + "','" + boxCidade.Text + "','" + boxContato.Text + "','" + boxEndereco.Text + "','" + boxBairro.Text + "','" + boxCep.Text + "','" + boxFone1.Text + "','" + boxFone2.Text + "','" + boxCel1.Text + "','" + boxCel2.Text + "','" + boxEmail.Text + "','" + boxComment.Text + "');";
            //MessageBox.Show(salvar);
            conn.executaInstrucao(salvar);
            //conn.executaInstrucao("commit;");
        }
        catch (Exception g)
        {
            MessageBox.Show("Problema na conexão");
        }

    }

这是带有一些随机值的输出字符串,在 SQL Developer 上工作并实际添加了行:

INSERT INTO Client(Name, Document, City, Contact, Addr, District, Zipcode, Phone_1, Phone_2, Cel_1, Cel_2, eymael, tobar) VALUES('asdassdsad', '15.465.465/4654-54','654654654','654654654','654654654','654654654','65465-465','(65) 4654-6546','(54) 6546-5465','(46) 54654-6546','(65) 46546-5465','4654654654','65465465465');

请有人帮助我。我不知道出了什么问题。

PS.:我所有的列都是 VARCHAR2。

【问题讨论】:

标签: c# sql .net oracle11g


【解决方案1】:

ORA 00911 是无效字符问题。如果您的文本框中有 ' 字符,可能会出现问题。像上面的评论一样使用 SqlCommand.Parameters.AddWithValue 就像 Soner Gönül 说的parameter

【讨论】:

  • 参数化效果很好,但实际问题是“;”到底。相当愚蠢的错误,大声笑。谢谢你,好心的先生。
猜你喜欢
  • 2013-03-08
  • 2013-02-21
  • 2017-06-10
  • 1970-01-01
  • 1970-01-01
  • 2013-02-18
  • 1970-01-01
  • 1970-01-01
  • 2014-05-17
相关资源
最近更新 更多