C# Code Listing for BatchQueryFindAnEmp

This feature will be removed in a future version of Microsoft SQL Server. Avoid using this feature in new development work, and plan to modify applications that currently use this feature.

The following sample creates BatchQueryFindAnEmp.

private void BatchQueryFindAnEmp_Click(System.Object sender, System.EventArgs e)
{
   server.sql_endpoint proxy = new server.sql_endpoint ();
   proxy.Credentials = System.Net.CredentialCache.DefaultCredentials;
   listBox1.Items.Add ("1) Executing batch.  ");
   listBox1.Items.Add ("");
   NativeSOAPApp1.server.SqlParameter[] p = new NativeSOAPApp1.server.SqlParameter[1];

   p[0] = new NativeSOAPApp1.server.SqlParameter ();
   p[0].name = "x";
   p[0].Value = textBox1.Text;
   p[0].maxLength = 20;
   p[0].sqlDbType = NativeSOAPApp1.server.SqlDbType.Int;
   p[0].direction = NativeSOAPApp1.server.ParameterDirection.Input;
   if (textBox1.Text == "NULL" || textBox1.Text == "null")
p[0].Value = null;

   string s = "SELECT EmployeeID, FirstName, LastName " + "FROM Employee Where EmployeeID=@x  " + "FOR XML AUTO;";
   object[] results = proxy.sqlbatch (s, ref p);// proxy.sqlbatch(s);

   for (int j = 0; j < results.Length; j++)
   {
object e1;
server.SqlMessage errorMessage;
System.Xml.XmlElement xmlResult;

//System.Data.DataSet resultDS;
e1 = results[j];

//return value from SP is an int
if (e1.GetType ().IsPrimitive)
{
   listBox1.Items.Add ("Return code = ");
   listBox1.Items.Add (e1);
}

switch (e1.ToString ())
{
   case "NativeSOAPApp1.server.SqlRowCount":
listBox1.Items.Add (e1.ToString ());
listBox1.Items.Add (((NativeSOAPApp1.server.SqlRowCount)results[j]).Count);
break;

   case "System.Xml.XmlElement":
xmlResult = (System.Xml.XmlElement)results[j];
listBox1.Items.Add (xmlResult.OuterXml);
break;

   case "NativeSOAPApp1.server.SqlMessage":
errorMessage = (server.SqlMessage)results[j];
listBox1.Items.Add (errorMessage.Message);
listBox1.Items.Add (errorMessage.Source);
break;
}
   }
}