如何将adoDB连接转换为SqlConnection? [英] How to convert adoDB connection to SqlConnection?

查看:122
本文介绍了如何将adoDB连接转换为SqlConnection?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

        Dim sString As String
        Dim sSql As String
        Dim sRS As New ADODB.Recordset
        Dim sConn As New ADODB.Connection
        Dim X As Integer
        Dim Y As Integer

        Me.lstEx.Text = ""
        sString = ""
        sSql = "Select TalentID From tbl_talent_databaseOrder by TalentID"
        sConn = CurrentProject.Connection
        sRS.Open(sSql, sConn, adOpenKeyset, adLockOptimistic)
        If Not sRS.EOF Then
            With sRS
                X = 0
                .MoveFirst()
                Do Until .EOF
                    Y = !TalentID
ChkSeq:
                    X = X + 1
                    If Y <> X Then 'chk to see if TalentID is sequential
                        sString = sString & X & " "  'if it is not, then record the non sequential number into the string
                        GoTo ChkSeq
                    End If
                    .MoveNext()
                Loop
            End With
        End If
        Me.lstEx.Text = sString
        sRS = Nothing





如何将上述代码转换为赞美SqlConnection?



How do i convert the above codes to compliment SqlConnection?

推荐答案

这里有更多的连接字符串,

显示如何使用OLEDB连接到数据源。

Conn String





这里是与上述代码块等效的MS-SQL兼容转换代码。

Here are more connection strings for you,
that show how to use connect to a datasource using OLEDB.
Conn String


And here is the MS-SQL compatible converted code equivalent of your above codeblock.
Function SomeKnockeUpCode() As String

	Dim intX As Integer = Nothing
	Dim intY As Integer = Nothing
	Dim strSting As String = Nothing
	Dim strSqlQUery As String = Nothing
	Dim cmdSqlCommand As Data.SqlClient.SqlCommand = Nothing
	Dim rdrDataReader As Data.SqlClient.SqlDataReader = Nothing

	'------------------------------------------------------------------------------------------------------------------------
	'-> Process
	'------------------------------------------------------------------------------------------------------------------------
	strSqlQUery = "Select TalentID From tbl_talent_database Order by TalentID"
	msSqlConnection = New Data.SqlClient.SqlConnection()
	'NOTE - You may need to CHECK your connection string!!! in the line below
	msSqlConnection.ConnectionString = CurrentProject.Connection
	cmdSqlCommand = New Data.SqlClient.SqlCommand(strSqlQUery, msSqlConnection)
	If cmdSqlCommand.Connection.State = Data.ConnectionState.Closed Then cmdSqlCommand.Connection.Open()
	rdrDataReader = cmdSqlCommand.ExecuteReader()
	If rdrDataReader.HasRows Then
		Do While rdrDataReader.Read()
			intX = 0
			intY = rdrDataReader.GetValue(rdrDataReader.GetOrdinal("TalentID"))
			Do While intX <> intY
				intX = intX + 1
				If intX <> intY Then
					strSting = strSting & intX & " "	'if it is not, then record the non sequential number into the string
				Else
					Exit Do
				End If
			Loop
		Loop
	End If
	If cmdSqlCommand.Connection.State = Data.ConnectionState.Open Then cmdSqlCommand.Connection.Close()
	'return string
	Return strSting
	'tidy up
	intX = Nothing
	intY = Nothing
	strSting = Nothing
	strSqlQUery = Nothing
	cmdSqlCommand = Nothing
	rdrDataReader = Nothing

End Function


我认为你可以使用OLEDB管理它

不引用因为我不是110%肯定。



也许这个页面将为您提供更多信息
I think you can manage it using OLEDB
Dont quote me on that as im not 110% sure.

Maybe this page will give you more info


我有关于sqlconnection的问题

是否有使用udl文件的sqlconnection代码或者此文件无法链接用sqlconnection ??
i'v a question about sqlconnection
is there code for sqlconnection using udl file or this file can't link with sqlconnection??


这篇关于如何将adoDB连接转换为SqlConnection?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆