Export (0) Print
Expand All

Visual Basic Code Listing for FindAnEmp

The following code creates FindAnEmp.

  Dim proxy As New server.sql_endpoint
  Dim response As New Object
  Dim resultXml As System.Xml.XmlElement
  Dim errorMessage As server.SqlMessage
  Dim outputParam As System.Int32
  Dim param
  Dim i As System.Int16
  Dim rowCount As server.SqlRowCount
  Dim outParam As server.SqlParameter

  param = TextBox1.Text
  proxy.Credentials = System.Net.CredentialCache.DefaultCredentials
  ListBox1.Items.Add("1) Executing batch.  ")
  ListBox1.Items.Add("")

  Dim p(1) As server.SqlParameter
  p(0) = New server.SqlParameter
  p(0).name = "x"
  p(0).Value = TextBox1.Text
  p(0).maxLength = 20
  p(0).direction = server.ParameterDirection.Input
  If (TextBox1.Text = "NULL" Or TextBox1.Text = "null") Then
p(0).Value = Nothing
  End If
  Dim s As String
  s = "SELECT FirstName, LastName " + "FROM  Employee Where EmployeeID=@x " + "FOR XML AUTO"
  response = proxy.sqlbatch(s, p)

  ' loop through response object array to find the individual items
  For i = 0 To Microsoft.VisualBasic.UBound(response)
If (response(i).GetType.IsPrimitive) Then
    ListBox1.Items.Add("Printing Returned Code from SP:")
    ListBox1.Items.Add("The type of the element in obj array is: ")
    ListBox1.Items.Add(response(i).GetType())
    ListBox1.Items.Add("Return Code = ")
    ListBox1.Items.Add(response(i))
End If
Select Case response(i).GetType().ToString()
    Case "System.Xml.XmlElement"
  ListBox1.Items.Add("Printing result of SELECT ...FOR XML")
  ListBox1.Items.Add("The type of the result in obj array is: ")
  ListBox1.Items.Add(response(i).ToString())
  ListBox1.Items.Add("This is the result :")
  resultXml = response(i)
  ListBox1.Items.Add(resultXml.OuterXml)
    Case "server.SqlMessage"
  errorMessage = response(i)
  ListBox1.Items.Add("Printing error msg, warning or other informational msg:")
  ListBox1.Items.Add("The type of the corresponding  obj array element is: ")
  ListBox1.Items.Add(errorMessage.ToString())
  ListBox1.Items.Add("This is the msg :")
  ListBox1.Items.Add(errorMessage.Message)
  ListBox1.Items.Add(errorMessage.Source)
    Case "server.SqlRowCount"
  ListBox1.Items.Add("Printing Sql Row count returned")
  ListBox1.Items.Add("The type of the row count element in obj array is: ")
  ListBox1.Items.Add(response(i).ToString())
  ListBox1.Items.Add("Row count =")
  rowCount = response(i)
  ListBox1.Items.Add(rowCount.Count)
    Case "server.SqlParameter"
  ListBox1.Items.Add("Printing output params:")
  ListBox1.Items.Add("The type of the corresponding  obj array element is: ")
  ListBox1.Items.Add(response(i).ToString())
  ListBox1.Items.Add("Outparam name is :")
  outParam = response(i)
  ListBox1.Items.Add(outParam.name)
  ListBox1.Items.Add("Outparam value is :")
  ListBox1.Items.Add(outParam.Value)
End Select
  Next

Community Additions

ADD
Show:
© 2014 Microsoft