Share via


C# Code for BatchQueryFindAllEmps

The following sample creates BatchQueryFindAllEmps.

private void BatchQueryFindAllEmps_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 = null;
   string s = "SELECT FirstName, LastName " + "FROM  Employee " + "FOR XML AUTO;";
   object[] results = proxy.sqlbatch (s, ref p);

   for (int j = 0; j < results.Length; j++)
   {
object e1;
server.SqlMessage errorMessage;
System.Xml.XmlElement xmlResult;
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 ("Printing Sql Row count returned");
listBox1.Items.Add ("The type of the row count element in obj array is: ");
listBox1.Items.Add (e1.ToString ());
listBox1.Items.Add ("Row count =");
listBox1.Items.Add (((NativeSOAPApp1.server.SqlRowCount)results[j]).Count);
break;

   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 (e1.ToString ());
listBox1.Items.Add ("This is the result :");
xmlResult = (System.Xml.XmlElement)results[j];
listBox1.Items.Add (xmlResult.OuterXml);
break;

   case "NativeSOAPApp1.server.SqlMessage":
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 (e1.ToString ());
listBox1.Items.Add ("This is the msg :");
errorMessage = (server.SqlMessage)results[j];
listBox1.Items.Add (errorMessage.Message);
listBox1.Items.Add (errorMessage.Source);
break;
}
   }
}

See Also

Reference

Sending SOAP Requests by Using Visual Studio 2005 Client (C#)

Help and Information

Getting SQL Server 2005 Assistance