插入表时出现语法错误

时间:2014-05-13 05:41:04

标签: sql vb.net postgresql

我的桌子

    CREATE TABLE tbl_region
(
  id integer,
  "desc" character varying(100)
)

以下是我在VB.NET中向INSERT写入上述表格的代码

 Using conn As New NpgsqlConnection("Server=" & gstrServerName & ";Port=" & gstrPort & ";Database=" & gStrDBName & ";Username=" & gstrUserName & ";Password=" & gPassword)
        conn.Open()
        Dim cmd As New NpgsqlCommand
        cmd.Connection = conn
        cmd.CommandText = _
        "INSERT INTO TBL_REGION(ID,DESC)" & _
        "VALUES(@ID,@DESC)"
        Dim paramID As NpgsqlParameter = New NpgsqlParameter("@ID", NpgsqlTypes.NpgsqlDbType.Integer)
        Dim paramDESC As NpgsqlParameter = New NpgsqlParameter("@DESC", NpgsqlTypes.NpgsqlDbType.Char, 100)
        paramID.Value = 1
        paramDESC.Value = "worlds region"

        cmd.Parameters.Add(paramID)
        cmd.Parameters.Add(paramDESC)
        cmd.Prepare()
        cmd.ExecuteNonQuery()
    End Using

我正在获得ERROR: 42601: syntax error at or near "DESC"

on

 cmd.Prepare()
  

数据库:Postgresql

1 个答案:

答案 0 :(得分:1)

DESC是SQL中的保留关键字。使用其他名称,如“DESCRIPT”,你应该没问题