.NET中的ADODB替代方案

时间:2014-08-22 13:54:56

标签: .net vb6

我正在将vb6转换为.net。我需要将其转换为.net。我可以用dbdccommand吗?

Public Const CN As String = "Driver={SQL Server};Server=TESTDB;Database=DBA;User Id=DBO;PassWord=dbotest;"

cmd = New ADODB.Command
            rs = New ADODB.Recordset

            With cmd
                .let_ActiveConnection(CN)
                .CommandType = ADODB.CommandTypeEnum.adCmdStoredProc
                .CommandText = "s_Servers"
                rs = cmd.Execute
            End With

3 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

Using cnn as New SqlCommand("Driver={SQL Server};Server=TESTDB;Database=DBA;User Id=DBO;PassWord=dbotest;")
  cnn.Open
    Using cmd as SQLCommand = cnn.CreateCommand()
      cmd.CommandType = CommandType.StoredProcedure
      cmd.CommandText = "s_Servers"
      Using da as New SQLDataAdapter
        da.SelectCommand = cmd
        Using ds as New DataSet
          da.fill(ds)
          ' here's where you figure out how to work with a dataset
          ' you can take it from here
        End Using
      End Using
    End Using
  End Using

答案 2 :(得分:0)

我找到了办法。

        Dim serverNm As Object
        Using connection As New SqlConnection(CN)
            Dim command As New SqlCommand
            command.Connection = connection
            command.CommandType = CommandType.StoredProcedure
            command.CommandText = "s_Servers"

            connection.Open()
            Using readerObj As SqlClient.SqlDataReader = command.ExecuteReader()
                While readerObj.Read
                    serverNm = readerObj("ServerNm")
                End While
            End Using
            connection.Close()
        End Using