Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
|
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old April 13th, 2007, 10:07 AM
Registered User
 
Join Date: Apr 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jscammell
Default Using SaveFileDialog to save SQL DB file

I'm trying to use the SaveFileDialog to save or export the SQL DB file to an email-able xls or text file type, but I can't seem to get the coding right. I can't find where the .xls extension is available in the coding. I've looked through the help pages and found it frustratingly without the actual saving code I was looking for. Any help would be greatly appreciated.
 
Old April 13th, 2007, 01:58 PM
Friend of Wrox
 
Join Date: Nov 2004
Posts: 1,621
Thanks: 1
Thanked 3 Times in 3 Posts
Default

This would be in the Filter property.
 
Old April 13th, 2007, 02:05 PM
Registered User
 
Join Date: Apr 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jscammell
Default

Thanks, but I'm not sure where the filter property is...currently this is how I'm exporting it to an xml file, but when I try to open with ms excel I get a conglomerate of informaiton that is close to useless. I'd like to be able to detail how the colum headers look as well as how the data is displayed, but since I am relatively new to this, it's kinda hard to figure out.


Code:

Public Function ExportContactData(ByVal UserID As Integer, ByVal ExportDataLocation As String) As Boolean

        With My.Computer.FileSystem
            If .FileExists(ExportDataLocation) Then .DeleteFile(ExportDataLocation)
        End With

        Dim GetContactAdapter As New Tracker1DataSetTableAdapters.Table1TableAdapter
        Dim GetContactTable As New Tracker1DataSet.Table1DataTable
        GetContactAdapter.Fill(GetContactTable)
        GetContactTable.WriteXml(ExportDataLocation)

        Return True
    End Function
 
Old April 14th, 2007, 06:39 AM
Registered User
 
Join Date: Apr 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jscammell
Default

I found the filter property, but with what I have seen so far I'm unable to find a function such as xmlwriter or writexml that would allow to write the table data as a continuous line of data directly to the output file. I really want to stay away from having to use an array to write the data, then come right back and import that as a CSV table. If any could help me out with some advice I'd really appreciate it.
 
Old April 14th, 2007, 10:02 AM
Registered User
 
Join Date: Apr 2007
Posts: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to jscammell
Default

I found an article on MS's MSDN forume that helped me a little bit, but I am needing some serious help with editting the code to get it to work. Now I'm getting an error saying that the file type .mdf is not a know file type for the following code:

Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
            "C:\Documents and Settings\jscammel\My Documents\Visual Studio 2005\Projects\Resolution Tracker\Resolution Tracker\Tracker1.mdf;"
        Dim objConn As New System.Data.OleDb.OleDbConnection(strConn)

        Try
            objConn.Open()

            'Fill a dataset with records from the Customers table.
            Dim strSQL As String
            Dim objDataset As New DataSet()
            Dim objAdapter As New System.Data.OleDb.OleDbDataAdapter()
            strSQL = "Select Contact Number, Lead ID, CSA ID, Customer ID, Order ID, OU, Reason Code, Date, CSNet, BlurbDB, Wizard, Help Pages, Knowledge Center, Website, E-mail, Tech CSNet, Sharepoint, Handouts, Inquiry, EscalationT, Escalation, Reason Why Not, Comments From Table1"
            objAdapter.SelectCommand = New System.Data.OleDb.OleDbCommand( _
                strSQL, objConn)
            objAdapter.Fill(objDataset)

            ' Create the FileStream to write with.
            Dim strFilename As String
            strFilename = "C:\Documents and Settings\All Users\Desktop\ContactLog.xml"
            Dim fs As New System.IO.FileStream(strFilename, _
                System.IO.FileMode.Create)

            'Create an XmlTextWriter for the FileStream.
            Dim xtw As New System.Xml.XmlTextWriter(fs, _
                System.Text.Encoding.Unicode)

            'Add processing instructions to the beginning of the XML file, one
            'of which indicates a style sheet.
            xtw.WriteProcessingInstruction("xml", "version='1.0'")
            'xtw.WriteProcessingInstruction( _
            ' "xml-stylesheet", "type='text/xsl' href='customers.xsl'")

            'Write the XML from the dataset to the file.
            objDataset.WriteXml(xtw)
            xtw.Close()

            MsgBox("Contact data has been exported to C:\Documents and Settings\All Users\Desktop\ContactLog.xml")

        Catch ex As Exception
            MsgBox(ex.Message)
        End Try


Ideally, I'd like to make the location string less static so that I could move the attachment with the program and I'd like to know if there is a way I could edit the code to accept the .mdf file, or is there a way I can translate to a .mdb file?





Similar Threads
Thread Thread Starter Forum Replies Last Post
Save a text file on SQL Server petercyriljones SQL Server DTS 2 January 3rd, 2007 07:35 AM
Save images in Sql Db itHighway SQL Server 2000 5 October 18th, 2006 10:39 AM
Howto save a Filename uploaded file to db? GigaBear ASP.NET 2.0 Basics 10 June 22nd, 2006 05:10 PM
Save Images in Sql Db itHighway Classic ASP Basics 7 August 10th, 2005 01:07 AM
moving a SQL Server v7 db file lcsgeek Classic ASP Databases 1 May 5th, 2004 01:23 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.