当前位置: 代码迷 >> ASP.NET >> asp.net 向oracle数据库插入值异常
  详细解决方案

asp.net 向oracle数据库插入值异常

热度:9430   发布时间:2013-02-25 00:00:00.0
asp.net 向oracle数据库插入值错误
l_com = New OracleCommand("insert into city values(id,cityid,cityname,citytype,'admin','','')", l_con)

  Dim l_id As OracleParameter = New OracleParameter("id", OracleType.Number)
  l_id.Direction = ParameterDirection.Input
  l_id.Value = System.DBNull.Value
  l_com.Parameters.Add(l_id)

  Dim l_cityid As OracleParameter = New OracleParameter("cityid", OracleType.VarChar)
  l_cityid.Direction = ParameterDirection.Input
  l_cityid.Value = l_dt.Rows.Item(i).Item("code")
  l_com.Parameters.Add(l_cityid)

  Dim l_cityname As OracleParameter = New OracleParameter("cityname", OracleType.VarChar)
  l_cityname.Direction = ParameterDirection.Input
  l_cityname.Value = l_dt.Rows.Item(i).Item("name")
  l_com.Parameters.Add(l_cityname)

  Dim l_citytype As OracleParameter = New OracleParameter("citytype", OracleType.Number)
  l_citytype.Direction = ParameterDirection.Input
  If i < 34 Then
  l_citytype.Value = 0
  ElseIf i > 33 Then
  l_citytype.Value = 1
  ElseIf i > 375 Then
  l_citytype.Value = 2
  End If
  l_com.Parameters.Add(l_citytype)

  l_com.ExecuteNonQuery()

其中id为在数据库中写的触发器实现自增的变量,city表的字段为

ID INTEGER
CITYID VARCHAR2(32)
CITYNAME N VARCHAR2(30)
CITYTYPE N NUMBER
OPERATOR N VARCHAR2(50)
OPERDATE N DATE
REMARK VARCHAR2(50)
谁能帮忙看看,为什么每次插入的时候都告诉我变量类型或者数量错误

------解决方案--------------------------------------------------------
把变量前面加上冒号就可以,这个问题解决了,谢谢
  相关解决方案