I got this code from M$ and it doesn't work, can anyone tell me why.I am trying to import data from a SQL database using a M$ access front end. Then export it to a XML page.
I have created a form with a command button and inserted the code below, but it comes back with a compile error and higlights the try.
I have changed the user id and password and the data source to my database mercy.
Try
Dim cn As New System.Data.SqlClient.SqlConnection()
cn.ConnectionString = _
"data source=(mercy);initial catalog=pubs;" & _
"User ID=sa;Password=!sa789"
cn.Open()
Dim cmd As New System.Data.SqlClient.SqlCommand()
cmd.Connection = cn
cmd.CommandText = "SELECT * FROM F_Pat_Present FOR XML AUTO, XMLDATA"
Dim xmlr As System.XML.XmlReader
xmlr = cmd.ExecuteXmlReader()
xmlr.Read()
Do While xmlr.ReadState <> XML.ReadState.EndOfFile
System.Diagnostics.Debug.WriteLine (xmlr.ReadOuterXml())
Loop
MessageBox.Show ("Reached the end. Check the output window.")
Catch ex As Exception
MessageBox.Show (ex.Message)
End Try
I have created a form with a command button and inserted the code below, but it comes back with a compile error and higlights the try.
I have changed the user id and password and the data source to my database mercy.
Try
Dim cn As New System.Data.SqlClient.SqlConnection()
cn.ConnectionString = _
"data source=(mercy);initial catalog=pubs;" & _
"User ID=sa;Password=!sa789"
cn.Open()
Dim cmd As New System.Data.SqlClient.SqlCommand()
cmd.Connection = cn
cmd.CommandText = "SELECT * FROM F_Pat_Present FOR XML AUTO, XMLDATA"
Dim xmlr As System.XML.XmlReader
xmlr = cmd.ExecuteXmlReader()
xmlr.Read()
Do While xmlr.ReadState <> XML.ReadState.EndOfFile
System.Diagnostics.Debug.WriteLine (xmlr.ReadOuterXml())
Loop
MessageBox.Show ("Reached the end. Check the output window.")
Catch ex As Exception
MessageBox.Show (ex.Message)
End Try