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.Confi gurationSe ttings.App Settings(" SQLConnect ion") <<<<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_payab le;trusted _connectio n=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.Confi gurationSe ttings.App Settings(" SQLConnect ion")
Dim strConn1 as string = "server=knxdbpn1;database= acct_payab le;trusted _connectio n=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.Fi leSystemOb ject")
fso.CreateTextFile("M:\Dow nload\CE\I nvoices\CE IP_Upload. txt")
Set fil = fso.GetFile("M:\Download\C E\Invoices \CEIP_Uplo ad.txt")
Set ts = fil.OpenAsTextStream(ForWr iting)
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.Confi
Dim strConn as string = "server=knxdbpn1;database=
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.Confi
Dim strConn1 as string = "server=knxdbpn1;database=
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.Fi
fso.CreateTextFile("M:\Dow
Set fil = fso.GetFile("M:\Download\C
Set ts = fil.OpenAsTextStream(ForWr
Use this line before opening the connection...
.....
.....
DS = New DataSet()
myConn.Open()
.....
.....
.....
.....
DS = New DataSet()
myConn.Open()
.....
.....
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Wowzer! Boy did I miss you. You know my code so well.
You even answered some of the my upcoming questions...you rock!
You even answered some of the my upcoming questions...you rock!
>>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=
'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,myCon
'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