2012年7月26日 星期四

SQL Reader

  Dim cnStr As String =
"Data Source=.;Initial Catalog=Northwind;Integrated Security=true"
      
        Dim cn As New SqlConnection(cnStr)
      
        Dim cmd As New SqlCommand()
        cmd.Connection = cn
        cmd.CommandText = "select * from region"
      
        cn.Open()
        Dim dr As SqlDataReader = cmd.ExecuteReader()
      
        While dr.Read = True
            Dim id As Integer = Convert.ToInt32(dr("regionid"))
            Dim desc As String = dr.GetString(1)
          
            Response.Write(
                String.Format("id: {0} , desc : {1} <br/>", id, desc))
        End While
      
        dr.Close()
        cn.Close()

標籤: ,

0 個意見:

張貼留言

訂閱 張貼留言 [Atom]

<< 首頁