次の方法で共有


BatchQueryFindAllEmps の C# コード

次のサンプルでは、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;
}
   }
}

参照

関連項目

Visual Studio 2005 クライアントを使用した SOAP 要求の送信 (C#)

ヘルプおよび情報

SQL Server 2005 の参考資料の入手