M
Manuel Canas
Hello there,
I am using the VB.NET Standart Edition compiler and I would like to know if
this is not supported on this edition.
This is just a testing code from a book that I'm trying here and it builds
with no problem, but when I run it I get and error.
This is the code snipet;
Dim xml_Reader as XmlReader
xml_Reader = m_SqlCommand.ExecuteXmlReader()
This is the piece of code that always gets trapped at runtime.
This is the system message;
"An unhandled exception of type 'System.Data.SqlClient.SqlException'
occured in system.data.dll
Additional information: System error.
This is the complete code;
Imports System.Xml
Imports System.Data.SqlClient
Imports System.Data
Public Class Form2
Private conn As SqlConnection
Private m_sqlcommand As SqlCommand
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
conn = New SqlClient.SqlConnection("data source=P4-MAN\MSDE; initial
catalog=contacts; user ID=sa;password=sa")
Dim Query As String = "SELECT * FROM Contacts " & _
"WHERE LastName LIKE @LastNameMatch " & _
" AND FirstName LIKE @FirstNameMatch " & _
"FOR XML AUTO, XMLDATA"
m_sqlcommand = New SqlCommand(Query, conn)
m_sqlcommand.Parameters.Add("@LastNameMatch", SqlDbType.VarChar)
m_sqlcommand.Parameters.Add("@FirstNameMatch", SqlDbType.VarChar)
End Sub
Private Sub cmdList_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdList.Click
m_sqlcommand.Parameters(0).Value = txtLastName.Text
m_sqlcommand.Parameters(1).Value = txtFirstName.Text
conn.Open()
Dim xml_reader As XmlReader ----------------------------------------- These
two lines always fail
xml_reader = m_sqlcommand.ExecuteXmlReader() --------------- These two lines
always fail
Dim DataSet As New DataSet
DataSet.ReadXml(xml_reader, XmlReadMode.Fragment)
dgContacts.DataSource = DataSet.Tables(0)
xml_reader.Close()
conn.Close()
End Sub
End Class
Any one knows why this always fails? I get the same error with the
ExecuteScalar() method as well.
Thanks,
Manuel
I am using the VB.NET Standart Edition compiler and I would like to know if
this is not supported on this edition.
This is just a testing code from a book that I'm trying here and it builds
with no problem, but when I run it I get and error.
This is the code snipet;
Dim xml_Reader as XmlReader
xml_Reader = m_SqlCommand.ExecuteXmlReader()
This is the piece of code that always gets trapped at runtime.
This is the system message;
"An unhandled exception of type 'System.Data.SqlClient.SqlException'
occured in system.data.dll
Additional information: System error.
This is the complete code;
Imports System.Xml
Imports System.Data.SqlClient
Imports System.Data
Public Class Form2
Private conn As SqlConnection
Private m_sqlcommand As SqlCommand
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
conn = New SqlClient.SqlConnection("data source=P4-MAN\MSDE; initial
catalog=contacts; user ID=sa;password=sa")
Dim Query As String = "SELECT * FROM Contacts " & _
"WHERE LastName LIKE @LastNameMatch " & _
" AND FirstName LIKE @FirstNameMatch " & _
"FOR XML AUTO, XMLDATA"
m_sqlcommand = New SqlCommand(Query, conn)
m_sqlcommand.Parameters.Add("@LastNameMatch", SqlDbType.VarChar)
m_sqlcommand.Parameters.Add("@FirstNameMatch", SqlDbType.VarChar)
End Sub
Private Sub cmdList_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles cmdList.Click
m_sqlcommand.Parameters(0).Value = txtLastName.Text
m_sqlcommand.Parameters(1).Value = txtFirstName.Text
conn.Open()
Dim xml_reader As XmlReader ----------------------------------------- These
two lines always fail
xml_reader = m_sqlcommand.ExecuteXmlReader() --------------- These two lines
always fail
Dim DataSet As New DataSet
DataSet.ReadXml(xml_reader, XmlReadMode.Fragment)
dgContacts.DataSource = DataSet.Tables(0)
xml_reader.Close()
conn.Close()
End Sub
End Class
Any one knows why this always fails? I get the same error with the
ExecuteScalar() method as well.
Thanks,
Manuel