'string'类型的值无法转换为'Devart.data.postgresql.PgSqlParameter'

时间:2014-06-06 09:14:21

标签: vb.net postgresql sql-insert parameterized

以下是我的PostgreSQL表格结构和要插入表格的vb.net代码。使用Devart's Component For PostgreSQL Connect

  

表gtab83

    CREATE TABLE gtab83
(
  orderid integer NOT NULL DEFAULT nextval('seq_gtab83_id'::regclass),
  acid integer,
  slno integer,
  orderdte date
)
  

表gtab84

    CREATE TABLE gtab84
(
  orderdetid integer DEFAULT nextval('seq_gtab84_id'::regclass),
  productid integer,
  qty integer,
  orderid integer
)

插入上表的代码在

下面
        '1.)INSERT INTO gtab83(orderid,acid, slno, orderdte) VALUES (?, ?, ?);
        '2.)INSERT INTO gtab84(orderdetid,productid, qty, orderid)  VALUES (?, ?, ?);

        Try
            Dim cmd As PgSqlCommand = New PgSqlCommand("", Myconnstr)
            cmd.CommandText = _
            "INSERT INTO GTAB83(ACID,SLNO,ORDERDTE)" & _
            "VALUES " & _
            "(@acid,@slno,@orderdte);"
            Dim paramAcid As PgSqlParameter = New PgSqlParameter("@acid", PgSqlType.Int, 0)
            Dim paramSlno As PgSqlParameter = New PgSqlParameter("@slno", PgSqlType.Int, 0)
            Dim paramOrderdte As PgSqlParameter = New PgSqlParameter("@orderdte", PgSqlType.Date, 0)
            paramAcid = cboCust.SelectedValue
            paramSlno = txtOrderNO.Text #ERROR#
            paramOrderdte = (txtDate.Text, "yyyy-MM-dd") #ERROR#
        Catch ex As Exception

        End Try

错误:

  

类型'字符串'的值无法转换为' Devart.data.postgresql.PgSqlParameter'

1 个答案:

答案 0 :(得分:0)

我认为您需要将它们转换为Integerdatetime。也许是这样的:

paramSlno.Value = integer.Parse(txtOrderNO.Text)
paramOrderdte.Value =  DateTime.Parse(txtDate.Text)