访问DataTable中的数据

    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)
        Dim da As New SqlDataAdapter(cmd)
        Dim ds As DataSet
        Dim main As String = "main"
        da.Fill(ds, main)
        Dim dc As DataColumn
        For Each dc In ds.Tables(0).Columns
            Console.Write("{0,15}", dc.ColumnName)
        Next
        Console.Write(vbCtrLf)
        Dim dr As DataRow
        For Each dr In ds.Tables(0).Rows
            Dim i As Integer
            For i = 1 To ds.Tables(0).Columns.Count
                Console.Write("{0,15}", dr(i - 1))
            Next i
            Console.Write(vbCtrLf)
        Next
    End Sub
End Class

你可能感兴趣的:(Datatable)