更新功能在VB.NET中不起作用 [英] Update function not working in VB.NET

查看:170
本文介绍了更新功能在VB.NET中不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

目前我正在使用VB.NET开发一个系统。我有UPDATE的以下查询。当我在SQL Developer中运行时,此查询正常工作



 更新 CCS2_TBL_INSPECTION_STANDARD  SET  CCSEQREVITEM =:CCSEQREVITEM,
CCSREVEFFECTIVEDATE = TO_DATE(:CCSREVEFFECTIVEDATE,' DD / MM / YYYY' WHERE CCSEQID
=:CCSEQID







但是当我尝试在VB.net中应用此查询时,它无法正常工作。实际上,此更新功能的流程是可行的,但是当我更新数据时,它无法正常工作。例如,我想要更新名称从'Ali'到'Abu',当我点击更新按钮时,弹出窗口显示更新成功但名称不会更改为'Abu',它仍然是'Ali'。执行时没有错误。有人知道吗?



我的尝试:



 受保护的  Sub  editInspectionRev(eqid  As  字符串

Dim xSQL 作为 System.Text.StringBuilder
xSQL.AppendLine( 更新CCS2_TBL_INSPECTION_STANDARD
xSQL.AppendLine( SET
xSQL.AppendLine( CCSEQREVITEM =:CCSEQREVITEM,CCSREVEFFECTIVEDATE = TO_DATE (:CCSREVEFFECTIVEDATE,'DD / MM / YYYY')
xSQL.AppendLine( WHERE CCSEQID =:CCSEQID

使用 cn 作为 OracleConnection(ConString)
cn.Open()
Dim cmd 作为 OracleCommand(xSQL.ToString,cn)
cmd.Connection = cn


cmd.Parameters.Add( :CCSEQREVITEM,txtRevContent.Text)
cmd.Parameters.Add( :CCSREVEFFECTIVEDATE,txtRevEffDate.Text)


cmd.Parameters.Add( :CCSEQID,eqid)

cmd.ExecuteNonQuery()
cn.Close( )

结束 使用
success3.Visible =
DisplayRevisionDetails()

结束 Sub

解决方案

替换它:

 使用 cn 作为  OracleConnection(ConString)



with:

 使用 cn 作为  OracleConnection(ConString)_ 
使用 {。CommandType = CommandType .Text,.BindByName = True }





这应该有助于识别参数名称。



更多细节,你会在这里找到: Gotcha#1161:在Oracle中使用命名参数ODP.NET [ ^ ]


Currently I'm develop a system using VB.NET. I have the following query for UPDATE. This query is work when I run in SQL Developer

UPDATE CCS2_TBL_INSPECTION_STANDARD SET CCSEQREVITEM = :CCSEQREVITEM, 
CCSREVEFFECTIVEDATE = TO_DATE(:CCSREVEFFECTIVEDATE,'DD/MM/YYYY') WHERE CCSEQID 
= :CCSEQID




But when I try applied this query in VB.net, its not work. Actually the flow for this update function is work but when I update the data, it is not working. For example, I want update name from 'Ali' to 'Abu', when I click the update button, there popup windows says that "Update success" but the name is not change to 'Abu', it still 'Ali'. There no error when I execute. Anyone know?

What I have tried:

Protected Sub editInspectionRev(eqid As String)

    Dim xSQL As New System.Text.StringBuilder
    xSQL.AppendLine("UPDATE CCS2_TBL_INSPECTION_STANDARD")
    xSQL.AppendLine("SET")
    xSQL.AppendLine("CCSEQREVITEM = :CCSEQREVITEM, CCSREVEFFECTIVEDATE = TO_DATE(:CCSREVEFFECTIVEDATE,'DD/MM/YYYY')")
    xSQL.AppendLine("WHERE CCSEQID = :CCSEQID")

    Using cn As New OracleConnection(ConString)
        cn.Open()
        Dim cmd As New OracleCommand(xSQL.ToString, cn)
        cmd.Connection = cn


        cmd.Parameters.Add(":CCSEQREVITEM", txtRevContent.Text)
        cmd.Parameters.Add(":CCSREVEFFECTIVEDATE", txtRevEffDate.Text)


        cmd.Parameters.Add(":CCSEQID", eqid)

        cmd.ExecuteNonQuery()
        cn.Close()

    End Using
    success3.Visible = True
    DisplayRevisionDetails()

End Sub

解决方案

Replace this:

Using cn As New OracleConnection(ConString)


with:

Using cn As New OracleConnection(ConString) _
	With {.CommandType = CommandType.Text, .BindByName = True}



This should help in recognizing parameters by their names.

More details, you'll find here: Gotcha #1161: Using Named Parameters with Oracle ODP.NET[^]


这篇关于更新功能在VB.NET中不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆