다음을 통해 공유


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 클라이언트(C#)를 사용하여 SOAP 요청 보내기

도움말 및 정보

SQL Server 2005 지원 받기