Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Any easy way to create an XML table
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00709062
Message ID:
00710832
Views:
13
Roland,

First thing I would do is remove the line
Email.BodyEncoding = System.Text.Encoding.Unicode
This line can cause problems and is not necessary.

As far as your error, try adding the following line before sending the mail
SmtpMail.SmtpServer = "mail.< myserver >.com"
If that doesn't work then try the following:
Does the code run when you are logged in under an administrative account? Could not access object usually means either a permissions problem, or that the CDO for Win2000 dll is not registered.

Based on the description of the exception, it seems that the CDO are not installed on your Windows XP system (after Windows 2000 Microsoft did not ship CDO by default). You may install corresponding products (such as Office XP and Exchange) that will bring CDO onto your machine.

>Hi Cathi,
>
>The XML code part worked. Great!!! I've even added an XML schema to the the XL file. Thanks!!!!!!!!!!!!!!!!!!
>
>The following code that I changed for the email part does not work. I lost.
>
>====================Error Message========================================
>System.Web.HttpException: Could not access 'CDO.Message' object. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.Runtime.InteropServices.COMException (0x80040220): The "SendUsing" configuration value is invalid.
>
>
>====================Changed code===========================================
>Imports System.Data.SqlClient
>Imports System.Web.Mail
>
>Public Class Form1
> Inherits System.Windows.Forms.Form
>
>#Region " Windows Form Designer generated code "
>
> Public Sub New()
> MyBase.New()
>
> 'This call is required by the Windows Form Designer.
> InitializeComponent()
>
> 'Add any initialization after the InitializeComponent() call
>
> End Sub
>
> 'Form overrides dispose to clean up the component list.
> Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
> If disposing Then
> If Not (components Is Nothing) Then
> components.Dispose()
> End If
> End If
> MyBase.Dispose(disposing)
> End Sub
>
> 'Required by the Windows Form Designer
> Private components As System.ComponentModel.IContainer
>
> 'NOTE: The following procedure is required by the Windows Form Designer
> 'It can be modified using the Windows Form Designer.
> 'Do not modify it using the code editor.
> Private Sub InitializeComponent()
> '
> 'Form1
> '
> Me.AutoScaleBaseSize = New System.Drawing.Size(6, 15)
> Me.ClientSize = New System.Drawing.Size(392, 260)
> Me.Name = "Form1"
> Me.Text = "NHD Report - Create XML and Email"
>
> End Sub
>
>#End Region
>
> Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
>
> 'Connect to the data base and get the table
> Dim MyConnectionString As String = "Data Source=TS;Initial Catalog=Real_OfficeManager;Integrated Security=SSPI"
> Dim oConn As New SqlConnection(MyConnectionString)
> Dim dataSet As New DataSet()
> Dim getTable As New SqlDataAdapter("SELECT '1234' AS AccountId, Listing.MlsListingId AS OrderNumber, Listing.EscrowNumber, Listing.APN, Listing.StreetNumber, Listing.StreetDirection, Listing.StreetName, Listing.StreetType, Listing.StreetUnit, Listing.City, Listing.State, Listing.ZipCode, Listing.ZipCodeP4,'6789' AS Fips, Listing.NhdReport, Listing.MlsEntryDate FROM Listing WHERE (Listing.FileNum > 53400)", oConn)
> getTable.Fill(dataSet, "MyTable")
> dataSet.WriteXml("C:\NHDXMLFile.xml", XmlWriteMode.DiffGram)
>
> Dim Email As New MailMessage()
> Email.BodyFormat = MailFormat.Html
> Email.BodyEncoding = System.Text.Encoding.Unicode
> Email.Body = "My Body Text"
> Email.From = "rlsimpson@cbbakersfield.com"
> Email.To = "rlsimpson@cbbakerfield.com"
> Email.Subject = "CB Preferred - Request for NHD Reports"
> Dim XMLFile As New MailAttachment("C:\NHDXMLFile.xml", MailEncoding.Base64)
> Email.Attachments.Add(XMLFile)
> SmtpMail.Send(Email)
> End Sub
>End Class
>
>-----------------------------------------------------------------------
>What did I do to the email portion?
>
>Thanks!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
>Roland
>
>===========================================================================
>
>>You need to add the assembly as a reference to your project. To do that, you go into your Solution Manager, right click on "References", select Add Reference. When the dialog box appears, scrool down until you see "System.Web dll" in the listbox. Double click the file and then click on OK to close the dialog box. This will add the assemby to your project so you can reference it by adding an Imports statement as shown in the sample code.
>>
>>>Hi Cathi,
>>>
>>>Thanks for your help. I really need it.
>>>
>>>Do I create a new project and add this code to the Form1.vb code as the first lines?
>>>
>>>Thats what I tried.
>>>
>>>I received an error on the line Imports System.Web.Mail
>>>===========================================================================
>>> Imports System.Data.SQLClient
>>> Imports System.Web.Mail
>>>Public Class Form1
>>> Inherits System.Windows.Forms.Form
>>>etc
>>>===========================================================================
>>>
>>>Do I need something installed that I may not have installed?
>>>Thanks
>>>Roland
>>>- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
>>>
>>>>Here are some steps to do what you are looking for:
>>>>
>>>>Add to your project, a reference to the "System.Web" assembly. Use the Solution Manager to do this.
>>>>
>>>>At the top of your code page put the following imports statements:
>>>>
>>>>
>>>>Imports System.Data.SqlClient
>>>>Imports System.Web.Mail
>>>>
>>>>
>>>>Use the following sample code to extract the data and send the email. You will need to modify it to fit your situation:
>>>>
>>>>
>>>>'Connect to the data base and get the table
>>>>Dim MyConnectionString As String = "data source=localhost;initial catalog=Northwind;integrated security=SSPI"
>>>>Dim oConn As New SqlConnection(MyConnectionString)
>>>>Dim dataSet As New DataSet()
>>>>Dim getTable As New SqlDataAdapter("select * from customers", oConn)
>>>>getTable.Fill(dataSet, "MyTable")
>>>>dataSet.WriteXml("C:\MyXMLFile.xml")
>>>>
>>>>Dim Email As New MailMessage()
>>>>Email.BodyFormat = MailFormat.Html
>>>>Email.BodyEncoding = System.Text.Encoding.Unicode
>>>>Email.Body = "My Body Text"
>>>>Email.From = "myfromemail@yourcompany.com"
>>>>Email.To = "mytoemail@theircompany.com"
>>>>Email.Subject = "My Subject line"
>>>>Dim XMLFile As New MailAttachment("C:\MyXMLFile.xml", MailEncoding.Base64)
>>>>Email.Attachments.Add(XMLFile)
>>>>SmtpMail.Send(Email)
>>>>
>>>>
>>>>Compile the project into an EXE.
>>>>
>>>>To launch the EXE with schedule, you can put it in the task scheduler. You can open task scheduler by choosing [Start menu]->[settings]->[control panel]->[scheduled Tasks].
>>>>
>>>>
>>>>>Hi Cathi,
>>>>>
>>>>>New to VB and .net. Its been a big undertaking on my part to try to learn SQL, vb and .net. I really appreciate all the help I can get.
>>>>>
>>>>>Actually I would like to write a vb program to write the XML file to a directory on the server which would be run on a daily schedule and then schedule a way to ftp or email the file after the XML has been created or n one step if possible. Any easy solutions?
>>>>>
>>>>>Thanks a lot for your help....
>>>>>Roland
>>>>>
>>>>>===========================================================================
>>>>>
>>>>>>Are you saying you want to generate an XML file from a SQL Select statement? Are you using a DataSet inside of your Windows Form now? If so, then you can output the DataSet directly to XML using the GetXml method or the WriteXml method.
>>>>>>
>>>>>>>Hi,
>>>>>>>
>>>>>>>I need to create an XML Table from a Windows Form using an SQL table as the source.
>>>>>>>
>>>>>>>Know very little about XML.
>>>>>>>
>>>>>>>SELECT ClientNum, LastName, FirstName, SignificantOther, Address, City, State, ZipCode, AddressAfterClose, CityAfterClose, StateAfterClose, ZipAfterClose, HomePhone, WorkPhone, WorkPhoneExt, CellPhone, FaxNumber, EmailAddress, Comments, InsertDateTime FROM dbo.Client WHERE (LastName LIKE ?)
>>>>>>>
>>>>>>>How would I create the XML table with the result rows?
>>>>>>>
>>>>>>>Thanks
>>>>>>>Roland
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform