Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Database Firebird.NET提供程序中是否存在可更新的结果集和记录集?_Database_Vb.net_Firebird_Resultset_Recordset - Fatal编程技术网

Database Firebird.NET提供程序中是否存在可更新的结果集和记录集?

Database Firebird.NET提供程序中是否存在可更新的结果集和记录集?,database,vb.net,firebird,resultset,recordset,Database,Vb.net,Firebird,Resultset,Recordset,我昨天在.NET提供商那里试过Firebird。Firebird肯定会击败SQL Compact Edition。我对它的特点和精确性感到惊讶。但是当我在.NET提供程序中找不到可更新的记录集/结果集特性和函数时,我感到很难过。FBResultSet不包含任何内容,没有行添加、创建、修改,什么都不包含。任何人都知道Firebird的Ado.Net提供程序中是否存在此功能,因为没有文档。我希望得到帮助,因为我正在等待将Firebird集成到我的免费软件应用程序中。另外,如果有用于实现可更新记录集的

我昨天在.NET提供商那里试过Firebird。Firebird肯定会击败SQL Compact Edition。我对它的特点和精确性感到惊讶。但是当我在.NET提供程序中找不到可更新的记录集/结果集特性和函数时,我感到很难过。FBResultSet不包含任何内容,没有行添加、创建、修改,什么都不包含。任何人都知道Firebird的Ado.Net提供程序中是否存在此功能,因为没有文档。我希望得到帮助,因为我正在等待将Firebird集成到我的免费软件应用程序中。另外,如果有用于实现可更新记录集的替换函数,则返回ResultSet。请帮帮我


问候。

我去过那里,做完了,拿到了t恤。所以,当我感受到你的痛苦时,我会给你一些代码来帮助你

我使用存储过程(存储过程)来执行任何记录更新添加等操作。然后我编写了一个类包装器来调用存储过程

在这里输入代码

因此,使用存储过程的以下代码:

ALTER PROCEDURE SP_IU_BATCH (
    AUTYPE INTEGER,
    BATCHID INTEGER,
    MAT_BATCHID INTEGER,
    DOS DATE,
    FACILITYID INTEGER)
RETURNS (
    RTNIDX INTEGER)
AS
BEGIN
    IF (:AUTYPE = 0) THEN
    BEGIN
        FOR
            SELECT GEN_ID(GEN_BATCH_ID,1)
            FROM RDB$DATABASE
        INTO
            :RTNIDX
        DO
        BEGIN
            INSERT INTO BATCH (BATCHID, MAT_BATCHID, DOS, FACILITYID)
            VALUES (:RTNIDX, :MAT_BATCHID, :DOS, :FACILITYID);
        END
    END
    ELSE
    BEGIN
        UPDATE BATCH SET MAT_BATCHID=COALESCE(:MAT_BATCHID, MAT_BATCHID), DOS=COALESCE(:DOS, DOS),
        FACILITYID=COALESCE(:FACILITYID, FACILITYID)
        WHERE BATCHID=:BATCHID;
    END
END
您可以使用以下数据库包装器访问它:myfbdb.vb

    Imports FirebirdSql.Data.Firebird
Imports FirebirdSql.Data.Firebird.Services
Imports FirebirdSql.Data.Firebird.Isql
Imports System.IO

Public Class myfbdb

#Region " Private Variables "
    Private dbConn As FbConnection = Nothing, dbBatch As Batch = Nothing
    Private Const dbName As String = "yourdatabasename.fdb", dbUser As String = "SYSDBA", dbPass As String = "yourpassword"
#End Region

#Region " Private Methods "
    Private Sub Connect()
        If dbConn Is Nothing Then
            Try
                dbConn = New FbConnection(GetConnString)
            Catch ex As FbException
                RaiseError(ex)
            End Try
        End If
    End Sub

    Private Sub Initialize()
        dbBatch = New Batch
        dbBatch.dbConn = Me
    End Sub
#End Region

#Region " Private Functions "
    Private Function GetConnString() As String
        Dim rtnString As String = Nothing
        Dim fbCSB As New FbConnectionStringBuilder
        fbCSB.Database = dbName
        fbCSB.Password = dbPass
        fbCSB.UserID = dbUser
        fbCSB.ServerType = 1
        rtnString = fbCSB.ToString
        fbCSB = Nothing
        Return rtnString
    End Function
#End Region

#Region " Public Properties "
    Public ReadOnly Property cmdb() As FbConnection
        Get
            Return dbConn
        End Get
    End Property

    Public ReadOnly Property cmBatch() As Batch
        Get
            Return dbBatch
        End Get
    End Property
    End Property
#End Region

#Region " Public Methods "

#Region " New "
    Public Sub New()
        Connect()
        Initialize()
    End Sub
#End Region

#Region " Finalize "
    Protected Overrides Sub Finalize()
        MyBase.Finalize()
        Close()
        Unload()
    End Sub
#End Region

#Region " Unload "
    Public Sub Unload()
        If Not dbConn Is Nothing Then
            If dbConn.State = Data.ConnectionState.Open Then
                dbConn.Close()
            End If
            dbConn = Nothing
        End If
        UnInitialize()
    End Sub
#End Region

#Region " Open / Close "
    Public Sub Open()
        Try
            If Not dbConn Is Nothing Then
                If dbConn.State = Data.ConnectionState.Open Then
                    dbConn.Close()
                End If
                dbConn.Open()
            End If
        Catch ex As Exception
            RaiseError(ex)
        End Try
    End Sub

    Public Sub Close()
        If Not dbConn Is Nothing Then
            dbConn.Close()
        End If
    End Sub
#End Region

#End Region

End Class
下面是存储过程的批处理包装器:

    Imports FirebirdSql.Data.Firebird
Imports FirebirdSql.Data.Firebird.Services
Imports FirebirdSql.Data.Firebird.Isql

Public Class Batch

#Region " Private Variables "
    Private clsCM As myfbdb
#End Region

#Region " Private Enums "
    Private Enum AUType
        Add = 0
        Update = 1
    End Enum
#End Region

#Region " Stored Procedures "

#Region " Add / Update "
    Private Function AU_Batch(ByVal itmBatch As cmdbType_Batch, ByVal au As AUType) As Integer
        Try
            Dim rtnIndex As Integer = -1
            'Create Temporary Command
            Dim tmpTrans As FbTransaction = clsCM.cmdb.BeginTransaction
            Dim tmpSQLCommand As FbCommand = New FbCommand("SP_IU_BATCH", clsCM.cmdb, tmpTrans)
            tmpSQLCommand.CommandType = Data.CommandType.StoredProcedure

            'Add Parameters
            Dim prmAUType As FbParameter = tmpSQLCommand.Parameters.Add("@AUTYPE", FbDbType.Integer)
            Dim prmBatchID As FbParameter = tmpSQLCommand.Parameters.Add("@BATCHID", FbDbType.Integer)
            Dim prmMAT_BatchID As FbParameter = tmpSQLCommand.Parameters.Add("@MAT_BATCHID", FbDbType.Integer)
            Dim prmDOS As FbParameter = tmpSQLCommand.Parameters.Add("@DOS", FbDbType.Date)
            Dim prmFacilityName As FbParameter = tmpSQLCommand.Parameters.Add("@FACILITYNAME", FbDbType.VarChar, 250)
            Dim prmFacilityID As FbParameter = tmpSQLCommand.Parameters.Add("@FACILITYID", FbDbType.Integer)
            Dim prmRtnIdx As FbParameter = tmpSQLCommand.Parameters.Add("@RTNIDX", FbDbType.Integer)
            'Specify Output Parameters
            prmRtnIdx.Direction = Data.ParameterDirection.Output
            'Set the Parameter Values
            With itmBatch
                prmAUType.Value = CInt(au)
                prmBatchID.Value = .BatchID
                prmMAT_BatchID.Value = .MAT_BatchID
                prmDOS.Value = .DOS
                prmFacilityName.Value = clsCM.enc.EncryptString128Bit(.FacilityName, Crypt_Text(clsCM.ivKey))
                prmFacilityID.Value = .FacilityID
            End With

            'Execute the Stored Procedure
            tmpSQLCommand.ExecuteNonQuery()

            If au = AUType.Add Then
                rtnIndex = prmRtnIdx.Value
            End If

            tmpTrans.Commit()

            'Clean up
            tmpSQLCommand = Nothing
            Return rtnIndex
        Catch ex As Exception
            RaiseError(ex)
            Return Nothing
        End Try
    End Function
#End Region

#Region " Public Functions "
    Public Function AddBatch(ByVal itmBatch As cmdbType_Batch) As Integer
        Try
            clsCM.Open()
            Dim rtnInteger As Integer = AU_Batch(itmBatch, AUType.Add)
            clsCM.Close()
            Return rtnInteger
        Catch ex As Exception
            RaiseError(ex)
            clsCM.Close()
            Return Nothing
        End Try
    End Function

    Public Function UpdateBatch(ByVal itmBatch As cmdbType_Batch) As Integer
        Try
            clsCM.Open()
            Dim rtnInteger As Integer = AU_Batch(itmBatch, AUType.Update)
            clsCM.Close()
            Return rtnInteger
        Catch ex As Exception
            RaiseError(ex)
            clsCM.Close()
            Return Nothing
        End Try
    End Function
#End Region

#Region " Public Properties "
    Public WriteOnly Property dbConn() As CodingModuleDB
        Set(ByVal value As CodingModuleDB)
            clsCM = value
        End Set
    End Property
#End Region

End Class

这是很多代码,但我不得不用很难的方式来完成,结果很糟糕。我希望你能用这个来弥补你的差距,开始跑步。Firebird真的是一个很棒的数据库。

谢谢你的源代码。我不知道把什么放在哪里,以及如何调用特定函数来更新DataTable中的任何行。