How to: Visually configure the data source connection string (2)

Source: Internet
Author: User
Author: water and smoke

How to: Visually configure the data source connection string (1)

File adoconnectiondialog. VB

Option   Strict   Off
Namespace udata Namespace Udata. connectionui
Public   Class adoconnectiondialog Class Adoconnectiondialog

Private Gconnectionstring As   String   =   Nothing

Public   Property connectionstring () Property Connectionstring () As   String
Get
Return Gconnectionstring
End   Get

Set ( Byval Value As   String )
Gconnectionstring = Value
End   Set
End Property


Public   Function showdialog () FunctionShowdialog ()AsSystem. Windows. Forms. dialogresult

ReturnShowdialog (Nothing)
End Function

Public   Function showdialog () Function Showdialog ( Byval Owner As System. Windows. Forms. Form) As System. Windows. Forms. dialogresult
Dim Mresult As System. Windows. Forms. dialogresult = System. Windows. Forms. dialogresult. OK

Dim Adoconnection As   Object
Dim Datalinks As   Object   =   Createobject ( " Datalinks " )

If Owner Is   Nothing   Then
Datalinks. hwnd = Intptr. Zero
Else
Datalinks. hwnd = Owner. Handle
End   If

If Gconnectionstring Is   Nothing   Orelse Gconnectionstring. Trim. Equals ( String . Empty) Then   ' Create a string
Adoconnection = Datalinks. promptnew ()
Mresult =   IIF ( Not Adoconnection Is   Nothing , System. Windows. Forms. dialogresult. OK, system. Windows. Forms. dialogresult. Cancel)

Else   ' Edit Existing string
Adoconnection =   Createobject ( " ADODB. Connection " )
Adoconnection. connectionstring = Gconnectionstring
Mresult =   IIF (Datalinks. promptedit (adoconnection), system. Windows. Forms. dialogresult. OK, system. Windows. Forms. dialogresult. Cancel)
End   If

If Mresult = System. Windows. Forms. dialogresult. OK Then
Gconnectionstring = Adoconnection. connectionstring
End   If

Adoconnection =   Nothing
Datalinks =   Nothing

Return Mresult
End Function
End Class
End namespace

The preceding class visually generates or edits an adoconnection data source connection string. Test the function. Code As follows (note the namespace when using IT ): Dim T As   New Lzmtw. udata. connectionui. adoconnectiondialog
Private   Sub button2_click () Sub Button2_click ( Byval Sender As System. object, Byval E As System. eventargs) Handles Button2.click
If T. showdialog ( Me ) = Windows. Forms. dialogresult. OK Then
Console. writeline (T. connectionstring)
Else
Console. writeline ( " Cancel " )
End   If
End sub

The following processing key is how to convert the commonly used oleonstring of oledbconnection, odbcconnection, and sqlconnection to the connectionstring of adoconnection. It seems that this is not simple. It seems that you have to master some adoconnection-related features.
It has to be segmented. In the next section, the connection string characteristics of adoconnection

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.