2014年10月2日 星期四

使用 DataReader 擷取資料


http://msdn.microsoft.com/zh-tw/library/haa3afyz.aspx

static void RetrieveMultipleResults(SqlConnection connection)
{
    using (connection)
    {
        SqlCommand command = new SqlCommand(
          "SELECT CategoryID, CategoryName FROM dbo.Categories;" +
          "SELECT EmployeeID, LastName FROM dbo.Employees",
          connection);
        connection.Open();

        SqlDataReader reader = command.ExecuteReader();

        while (reader.HasRows)
        {
            Console.WriteLine("\t{0}\t{1}", reader.GetName(0),
                reader.GetName(1));

            while (reader.Read())
            {
                Console.WriteLine("\t{0}\t{1}", reader.GetInt32(0),
                    reader.GetString(1));
            }
            reader.NextResult();
        }
    }
}

-------------------------------------
ask1.CommandText = "Select Count(訂單.訂單編號) From 訂單 Where 訂單.訂單編號='" + TextBox95.Text + "' Or 訂單.客戶碼='" + TextBox109.Text + "'"

----------------------------------------
從 DataAdapter 填入 DataSet



 ask1.CommandText = "Select Count(訂單.訂單編號) From 訂單 Where 訂單.訂單編號='" + TextBox95.Text + "' Or 訂單.客戶碼='" + TextBox109.Text + "'"
            count = ask1.ExecuteScalar()
             '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
            Dim str(count, 7) As String

            For i = 1 To count
                ask1.CommandText = "Select 訂單編號 From 訂單 Where 訂單編號='" + TextBox95.Text + "' Or 客戶碼='" + TextBox109.Text + "'"
                str(i, 0) = ask1.ExecuteScalar()
                ask1.CommandText = "Select 客戶.簡稱 From 客戶,訂單 Where 客戶.客戶碼=訂單.客戶碼 And 訂單.訂單編號='" + TextBox95.Text + "'"
                str(i, 1) = ask1.ExecuteScalar()

                    TextBox100.Text = str(i, 0)
                    TextBox101.Text = str(i, 1)
             Next


沒有留言: