2010-12-03 5 views
0

Ich habe Firebird gestern mit .NET Provider ausprobiert. Firebird war sicher die SQL Compact Edition zu schlagen. Ich war erstaunt von seinen Eigenschaften und seiner Präzision. Aber ich war traurig, als ich die aktualisierbaren RecordSet/ResultSet Features und Funktionen im .NET Provider nicht finden konnte. FBResultSet enthält nichts, keine Zeilen Addition, Erstellung, Änderung, nichts. Jeder weiß, ob diese Funktion in Ado. Net-Provider von Firebird existiert, weil es keine Dokumentation gibt. Ich möchte Hilfe erhalten, weil ich darauf warte, Firebird in meine Freeware-Anwendung zu integrieren. Wenn Ersatzfunktionen für das Implementieren von aktualisierbarem RecordSet, ResultSet vorhanden sind. Bitte hilf mir.Gibt Updatable Resultset und Recordset in Firebird .NET Provider?

Grüße.

Antwort

1

Ich war dort, habe das gemacht und das T-Shirt bekommen. Also, als ich deinen Schmerz fühlte, werde ich dir einen Code geben, der dir helfen sollte.

Ich habe Stored Procedures (Sprocs) verwendet, um irgendwelche Record Update Additionen usw. zu machen. Dann schrieb ich einen Klassenwrapper, um die Sprocs aufzurufen.

Code eingeben hier

Also, mit diesem Code für die sproc:

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 

Sie würden es mit dieser Datenbank-Wrapper zuzugreifen: 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 

Und hier ist die Stapelwickler für den Sproc:

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 

Das war eine Menge Code, aber ich musste dies auf die harte Tour tun und es stank. Ich hoffe, Sie können dies nutzen, um Ihre Lücke zu schließen, um zum Laufen zu kommen. Firebird ist wirklich eine großartige Datenbank.

+0

Danke für den Quellcode. Ich weiß nicht, wo und wie ich eine bestimmte Funktion aufrufen soll, um eine Zeile aus der DataTable zu aktualisieren. – user529948

Verwandte Themen