使用数据读取器类SqlDataReader

   Sub main()
        Dim com As New SqlConnection()
        com.ConnectionString = "server=(local);database=test;uid=sa;pwd=;"
        Dim str As String = "select hotel_name,hotel_phone from main"
        Dim cmd As New SqlCommand(str, com)
        Try
            com.Open()
            Dim reader As SqlDataReader = cmd.ExecuteReader() '通过调用命令的 ExecuteReader 方法(例如 ExecuteReader)返回行
            While reader.Read() '使 SqlDataReader 前进到下一条记录
                Dim myInt As Int32
                Dim myString As String
                myInt = reader.GetInt32(0) '获取指定列的 32 位有符号整数形式的值
                myString = reader.GetString(1).ToString() '获取以本机格式表示的列的值。
            End While
            reader.Close()
        Finally
            com.Close()
        End Try

    End Sub
End Class

你可能感兴趣的:(reader)