当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET SqlDataReader.GetOrdinal方法代码示例

本文整理汇总了VB.NET中System.Data.SqlClient.SqlDataReader.GetOrdinal方法的典型用法代码示例。如果您正苦于以下问题:VB.NET SqlDataReader.GetOrdinal方法的具体用法?VB.NET SqlDataReader.GetOrdinal怎么用?VB.NET SqlDataReader.GetOrdinal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Data.SqlClient.SqlDataReader的用法示例。


在下文中一共展示了SqlDataReader.GetOrdinal方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。

示例1: ReadGetOrdinal

Private Sub ReadGetOrdinal(ByVal connectionString As String)
    Dim queryString As String = _
       "SELECT DISTINCT CustomerID FROM dbo.Orders;"

    Using connection As New SqlConnection(connectionString)
        Dim command As New SqlCommand(queryString, connection)
        connection.Open()

        Dim reader As SqlDataReader = command.ExecuteReader()

        ' Call GetOrdinal and assign value to variable.
        Dim customerID As Integer = reader.GetOrdinal("CustomerID")

        ' Use variable with GetString inside of loop.
        While reader.Read()
            Console.WriteLine("CustomerID={0}", reader.GetString(customerID))
        End While

        ' Call Close when done reading.
        reader.Close()
    End Using
End Sub
开发者ID:VB.NET开发者,项目名称:System.Data.SqlClient,代码行数:22,代码来源:SqlDataReader.GetOrdinal

示例2: MainClass

' 导入命名空间
Imports System
Imports System.Collections
Imports System.Data
Imports System.IO
Imports System.Xml.Serialization
Imports System.Xml
Imports System.Windows.Forms
Imports System.Data.SqlClient


Public Class MainClass
    Shared Dim WithEvents con As SqlConnection

    Shared Sub Main()
        con = New SqlConnection("Server=(local)\SQLEXPRESS;Initial Catalog=MyDatabase;Integrated Security=SSPI") 

        Dim cmd As New SqlCommand()

        cmd.CommandText = "SELECT * FROM Employee"
        cmd.Connection = con

        Try
            con.Open()
            Dim reader As SqlDataReader = cmd.ExecuteReader()
            Dim OrderIDIdx As Integer = reader.GetOrdinal("ID")
            'Dim OrderDateIdx As Integer = reader.GetOrdinal("FirstName")
            'Dim OrderFreightIdx As Integer = reader.GetOrdinal("LastName")

            Do
                While reader.Read()
                    Dim OrderID As Integer = reader.GetInt32(OrderIDIdx)
                    'Dim OrderDate As DateTime = reader.GetDateTime(OrderDateIdx)
                    'Dim OrderFreight As Decimal = reader.GetDecimal(OrderFreightIdx)

                    'Console.WriteLine(OrderID & vbTab & OrderDate & vbTab & OrderFreight)
                    Console.WriteLine(OrderID & vbTab )
                End While
            Loop While reader.NextResult()

            reader.Close()
        Finally
            con.Close()
        End Try
    End Sub
End Class
开发者ID:VB程序员,项目名称:System.Data.SqlClient,代码行数:46,代码来源:SqlDataReader.GetOrdinal


注:本文中的System.Data.SqlClient.SqlDataReader.GetOrdinal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。