VB School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB Expert!

Join 307,185 VB Programmers for FREE! Get instant access to thousands of VB experts, tutorials, code snippets, and more! There are 1,605 people online right now. Registration is fast and FREE... Join Now!




Creating a txt file from an SQL query within an if

 

Creating a txt file from an SQL query within an if

MoistFist

2 Jun, 2009 - 11:15 AM
Post #1

D.I.C Head
**

Joined: 2 Jun, 2009
Posts: 87


My Contributions

" So what i am trying to do is query from two databases and get results from both, but i want the querys to spit out a text file on my desktop, what imports or dim would i need, any help or samlpes, and i am wanting the code within the if statments below













Imports System.Data.SqlClient
Imports System.Runtime.InteropServices
Imports System.Array
Imports System.Net.Sockets
Imports System.Net.Sockets.TcpClient
Imports System
Imports System.Threading
Imports System.IO
Imports Microsoft.VisualBasic

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cn As New SqlConnection("Data Source=;User Id=;Password=")
Dim strSQLMTCensus As String = "Select Count(*) as MTCnt from altlivedb.dbo.EPRCensusMT"
Dim MaxRec As Integer
Dim MTAcctNum, MTUnitNum, strSQLBV As String
Dim MTAdmitDate As Date
Dim FSO
Dim mtEPRresults


cn.Open()
Dim dr As SqlDataReader

Dim cmd As New SqlCommand(strSQLMTCensus, cn)
dr = cmd.ExecuteReader

dr.Read()
MaxRec = CType(dr.Item("MTCnt").ToString, Integer)

dr.Close()

For Cnt As Integer = 1 To 1
Dim strSQL As String = "Select AccountNumber, UnitNumber, AdmitDateTime from altlivedb.dbo.EPRCensusMT Where RecID =" & Cnt
Dim dr1, dr2 As SqlDataReader

Dim cmd1 As New SqlCommand(strSQL, cn)
dr1 = cmd1.ExecuteReader




dr1.Read()
MTAcctNum = dr1.Item("AccountNumber").ToString
MTUnitNum = dr1.Item("UnitNumber").ToString
MTAdmitDate = dr1.Item("AdmitDateTime").ToString

strSQLBV = "SELECT UnitNumber, AccountNumber, Name, AdmitDateTime, DischargeDateTime " & _
"FROM BarVisits " & _
"WHERE (UnitNumber LIKE '%" & MTUnitNum & "%') AND (AccountNumber LIKE '%" & MTAcctNum & "%')"

'Dim cmd1 As New SqlCommand(strSQLBV, cn)'
cmd1.CommandText = strSQLBV
dr1.Close()
dr2 = cmd1.ExecuteReader()

dr2.Read()

If IsDBNull(dr2.Item("DischargeDateTime").Value) = True And IsDBNull(dr2.Item("AdmitDateTime").ToString) = False Then
'spit out text file"




ElseIf IsDBNull(dr2.Item("DischargeDateTime").Value) = True And IsDBNull(dr2.Item("AdmitDateTime").ToString) = True Then
'Send an A11 message to cancel'


End If


dr1.Close()
dr2.Close()
Next

cn.Close()

End Sub
End Class

User is offlineProfile CardPM
+Quote Post


June7

RE: Creating A Txt File From An SQL Query Within An If

2 Jun, 2009 - 05:29 PM
Post #2

D.I.C Regular
Group Icon

Joined: 9 Dec, 2008
Posts: 485



Thanked: 38 times
My Contributions
Do an Advanced Search (upper right of this page) on All Forums for 'data to text file'. There are some DIC threads on this topic might be helpful.

This post has been edited by June7: 2 Jun, 2009 - 05:29 PM
User is offlineProfile CardPM
+Quote Post

vb5prgrmr

RE: Creating A Txt File From An SQL Query Within An If

2 Jun, 2009 - 07:58 PM
Post #3

D.I.C Regular
***

Joined: 21 Mar, 2009
Posts: 486



Thanked: 30 times
My Contributions
wrong forum you need .net. PM a mod to have your thread moved

Thanks


User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/21/09 07:51PM

Live VB Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB Tutorials

Reference Sheets

VB Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month