hi,

Does anyone knows on how to update records from 1 text file into 2 different sql database.

Name of the sql Table is Payment2SQL_Success_P() & Payment2SQL_Success_E()
is the code below is on the right track.

Select Case "AGENCIES"
            Case AGENCY_AV Or AGENCY_SR Or AGENCY_IP Or AGENCY_TM Or AGENCY_MS
                PBillPayment = True
                EBillPayment = False
            Case AGENCY_AS Or AGENCY_CM
                PBillPayment = False
                EBillPayment = True
        End Select

        If blnPaymentDone = True Then
            If PBillPayment = True Then
                Payment2SQL_Success_P()
            ElseIf EBillPayment = True Then
                Payment2SQL_Success_E()
            End If
        End If

Ok, your code has nothing to do with updating records into 2 different database.

What I would like to know is:
A: Update a record into 2 different database, because the other one is essentially a backup database.
B: Update a record into only 1 database, but there are 2 different database depending on conditions. (As above u got a condition statement)
Example: A credit card payment software will have to update transaction records in Visa database and not Amex etc database, if the customer is paying by Visa. (I know it might not be happening in real world credit card processing software, but basically you got what I mean)

If what you meant is lateral, you may use a general Public Shared connection & commandtext like this

Public Shared conn As New connection 'Replace with OleConnection for Access and SqlConnection for SQL Database
Public Shared command As New Command 'Replace with OleCommand for Access and SqlCommand for SQL Database

And on Payment2SQL_Success_P() and Payment2SQL_Success_E() (Do both times)

'Constructor etc declaration are omitted for clarity
conn.connectionstring = "Data Source='" & pathToYourDatabaseVariable & "'"'Define your own connection string here.
command.connection = conn
command.commandtext ="update " 'Write your own database update query
conn.open()
command.executeNonQuery()
conn.close()

Of course, if that particular function does only updating of query and does not have other special code / function / things to do, then the above code will have 1 duplicate (The essential difference is the Connection String, thats all.)
Hence, for such case, i would recommend:

Select Case "AGENCIES"
            Case AGENCY_AV Or AGENCY_SR Or AGENCY_IP Or AGENCY_TM Or AGENCY_MS
                PBillPayment = True
                EBillPayment = False
            Case AGENCY_AS Or AGENCY_CM
                PBillPayment = False
                EBillPayment = True
        End Select

        If blnPaymentDone = True Then
            If PBillPayment = True Then
                conn.connectionstring = "Data Source=" & pathToYourDatabaseVariable & "'"'Define your own connection string here.
            ElseIf EBillPayment = True Then
               conn.connectionstring = "Data Source='" & pathToYourDatabaseVariable2 & "'"'Define your own connection string here.
            End If
       command.connection = conn
       command.commandtext ="update " 'Write your own database update query
       conn.open()
       command.executeNonQuery()
       conn.close()
        End If

For such case, always remember to put

Public Shared command As New command

etc, as listed above.

hi,

Does anyone knows on how to update records from 1 text file into 2 different sql database.

Name of the sql Table is Payment2SQL_Success_P() & Payment2SQL_Success_E()
is the code below is on the right track.

Select Case "AGENCIES"
            Case AGENCY_AV Or AGENCY_SR Or AGENCY_IP Or AGENCY_TM Or AGENCY_MS
                PBillPayment = True
                EBillPayment = False
            Case AGENCY_AS Or AGENCY_CM
                PBillPayment = False
                EBillPayment = True
        End Select

        If blnPaymentDone = True Then
            If PBillPayment = True Then
                Payment2SQL_Success_P()
            ElseIf EBillPayment = True Then
                Payment2SQL_Success_E()
            End If
        End If

By the way, if you meant one database (As in the database is in the same computer and same directory, but different table) then all you need to do is change the update query only. Thats all.

hi
i have send my code to your private message. Actualy your code is going well but it save's in both of the database's. I think something goes wrong with my condition statement which i'm not able to fix it.I wish you could help me.
the scenario is like this :
i save all the records in 1 text file (master and visa record) and when payment = true i want the records in the text file to be split according to its category and saves to where it suppose to be. if its master record it should save to master database with its accumulate total and if its visa record it should save to visa database with its accumulate total. both database having same table name as payment details .


Please guide. I realy appreciate if you could help me. thanx in advance

look, it might be tiring to just read the codes as I am too used to IDE.

Who ask you to save into 2 databases?

I mean, you should use only 1 command and 2 connections pre-defined, such that you change the command.connectionstring just before you open your database. Will that help?

Form 1

Public Shared Visaconn As New oleConnection
Public Shared Masterconn As New oleConnection

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
VisaConn.ConnectionString = ""'Connection String to Visa DB
MasterConn.ConnectionString = ""'Connection String to Masters DB
End Sub

If on same form, then on the subroutine (Sub) that opens, insert and / or update database

Dim command As New oleCommand
Dim hereconn As New oleConnection
If PM = "Visa" Then
command.conn = VisaConn
hereconn = Visaconn 'Public variable are meant to be the same template pre-defined in startup. Use local variable for local business only.
ElseIf PM = "Masters" Then
command.conn = MasterConn
hereconn = MasterConn
Else
'Up to you to decide
End If
command.commandtext = ""'Put your own update query string
hereconn.open()
command.executenonquery()
hereconn.close()
End Sub

Notes: If this updating of query is done on ANOTHER form, then please replace to

If PM = "Visa" Then
command.conn = [B]Form1.[/B]VisaConn
hereconn = [B]Form1.[/B]Visaconn 'Public variable are meant to be the same template pre-defined in startup. Use local variable for local business only.
ElseIf PM = "Masters" Then
command.conn = [B]Form1.[/B]MasterConn
hereconn = [B]Form1.[/B]MasterConn
Else
'Up to you to decide
End If

Add the bold will do, where Form1 is replaced by your application start's load form.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.