Link to home
Start Free TrialLog in
Avatar of klb37777
klb37777

asked on

Need help writing a text file - part 1

Hello all, I will have a lot of post about this subject since I just got it thrown on my lap and I have no idea how to do this. What I have to go by is VB code from a previous application, if I had more info then I could understand it more, but I don't.

I will post two questions on each until I feel more secure in what I need to do. Here is what I started....I really need to keep the connection to work through the calculations
1. How do I combine two sql tables in one connection or in one subroutine?


Sub Impact(sender As Object, e As System.EventArgs)
                 'Writing a textfile for Impact
                 
                'First connection for the terms table
                 'Dim strConn as string = System.Configuration.ConfigurationSettings.AppSettings("SQLConnection") <<<<need to keep this b/c it is used when app is on the server and not used when testing on my local host.
                 Dim strConn as string = "server=knxdbpn1;database=acct_payable;trusted_connection=true"
                 Dim mysql as string = "SELECT * tbl_ap_web_ce_inv_terms"
                 Dim myConn as New SqlConnection(strConn)
                 Dim objDR as SQLDataReader
                 Dim cmd as New SQLCommand(mySQL, myConn)
       Cmd.ExecuteNonQuery()

                 'Second connection string for account table
                 'Dim strConn1 as string = System.Configuration.ConfigurationSettings.AppSettings("SQLConnection")
                 Dim strConn1 as string = "server=knxdbpn1;database=acct_payable;trusted_connection=true"
                 Dim mysql1 as string = "SELECT * tbl_ap_web_ce_inv_account"
                 Dim myConn1 as New SqlConnection(strConn1)
                 Dim cmd1 as New SQLCommand(mySQL1, myConn1)
                 Cmd1.ExecuteNonQuery()

2.   Am I setting the following up correctly?...my application is done in VB.net, I am trying to use an example that was done in VB.


Set fso = CreateObject("Scripting.FileSystemObject")

fso.CreateTextFile("M:\Download\CE\Invoices\CEIP_Upload.txt")
Set fil = fso.GetFile("M:\Download\CE\Invoices\CEIP_Upload.txt")
Set ts = fil.OpenAsTextStream(ForWriting)

Avatar of DotNetLover_Baan
DotNetLover_Baan

Hi again,

>>How do I combine two sql tables in one connection or in one subroutine? <<
Use DataSet. Example:
 
First declare the DataSet as a global...   Dim DS As DataSet
Then ur Sub impact...

Sub Impact(sender As Object, e As System.EventArgs)
   Dim strConn as string = "server=knxdbpn1;database=acct_payable;trusted_connection=true"
   'Then write both the SQL strings togetther
   Dim mysql as string = "SELECT * FROM tbl_ap_web_ce_inv_terms; SELECT * FROM tbl_ap_web_ce_inv_account;""
   Dim myConn as New SqlConnection(strConn)
   'Then declare a DataAdapter to get the data
   Dim DA As New SqlDataAdapter(mysql,myConn)
   'Now open the connection and fill the DataSet with both the tables.
   myConn.Open()
   DA.Fill(DS)  'Here inside DS two tables will be created. Table(0) = tbl_ap_web_ce_inv_terms
                    'and Table(1) = tbl_ap_web_ce_inv_account
   MyConn.Close()
End Sub
Use this line before opening the connection...

.....
.....
DS = New DataSet()
myConn.Open()
.....
.....
ASKER CERTIFIED SOLUTION
Avatar of DotNetLover_Baan
DotNetLover_Baan

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of klb37777

ASKER

Wowzer! Boy did I miss you. You know my code so well.

You even answered some of the my upcoming questions...you rock!