ªð¦^¦Cªí ¤W¤@¥DÃD µo©«

[µo°Ý] VB2008 ³sµ² SQL2005 ³s½u°ÝÃD

[µo°Ý] VB2008 ³sµ² SQL2005 ³s½u°ÝÃD

½Ð±Ð¦U¦ì¤j¤j
  §Ú¥Ø«e¦b¾Ç²ßVB2008 ³s½u SQL2005
      °ÝÃD¡G·íµ{¦¡¬q°õ¦æ¨ì SQLconntion.open ®É¡A°õ¦æ«Ü¤[«á(¥Hsql³s½u®É¶¡)¡A´Nª½±µ¶}¥Xªí³æ¨Ó¡A¥i¬OSQLconntion.open «á¡AÀ³¸Ó­n°õ¦æsqlreader¡A½Ð°Ý¦U¦ì¤j¤j°ÝÃD¥X¦b¨º°Ú
   
¨Ï¥Î¤¸¥ó¡G¤U©Ô²M³æ(combobox)
      
   ps:vb6 ¸òvb2008¯uªº®t¤Ó¦h¤F¡A§Ú§¹¥þ¤£ª¾¹D°ÝÃD¥X¦b¨º , ½Ð¦U¦ì¥ý¶i«ü¾É)

µ{¦¡½X¡G

Imports System.Data
Imports System.Data.OleDb
Imports System.Data.SqlClient

Module Module1
    Public SPC_SQLPass$, SPC_SQLID$, SPC_SQLName$, SPC_SQLAdderss$
    Public IQC_SQLPass$, IQC_SQLID$, IQC_SQLName$, IQC_SQLAdderss$
   
Sub Load_main()
        Dim theCON As SqlConnection

        SPC_SQLPass = "samis"
        SPC_SQLID = "sa"
        SPC_SQLName = "Spc-Iqc"
        'SPC_SQLAdderss = "192-168-100-199\SQLEXPRESS"
        SPC_SQLAdderss = "Localhost"

        '³sµ²¸ê®Æ®w*************************************************************************************************************************************
        Dim ConnStr As String
        ConnStr = "Server=" & IQC_SQLAdderss & " ;Database=" & SPC_SQLName & " ;UID=" & IQC_SQLID & " WD=" & IQC_SQLPass
        ' Server=Localhost ¥Nªí¥»¾÷

        theCON = New SqlConnection(ConnStr)

        '************************************************************************************************************************************************
        
        '¸ê®Æ®w¬d¸ß*************************************************************************************************************************************
        Dim theCOMM As SqlCommand
        Dim theRST As SqlDataReader

        Dim mApp As String, mApp1 As String, mApp2 As String, mApp3 As String
        Dim strCMn As String

        mApp = "¬d¸ßÄæ¦ì"
        mApp1 = "Ãþ§O"
        mApp2 = ""
        mApp3 = "*"

        strCMn = "Select " & mApp3 & " From " & mApp & " " & mApp2 '³o¸Ìµ¹¤_SQL±Ô­z
     theCOMM = New SqlCommand(strCMn, theCON)

        '************************************************************************************************************************************************

        '¸ê®Æ®wLink Run**********************************************************************************************************************************
        theCON.Open()
        theRST = theCOMM.ExecuteReader()

        '************************************************************************************************************************************************
        If theRST.FieldCount > 0 Then

            Form1.ComboBox1.DataSource = theRST.Item(0)

        Else
            '§ä¤£¨ì¸ê®Æ
     End If

        '¸ê®Æ®wLink Close********************************************************************************************************************************
        theRST.Close()
        theCON.Close()
        '************************************************************************************************************************************************
    End Sub
End Module
¬O¾Çµ{¦¡¦Ó¤£¬O­nµ{¦¡¡A¬O¶i¨Bªº°ò¦

="= ¸Õ¥X¨Ó¤F
strCMn = "Server=" & SPC_SQLAdderss & ";database=" & SPC_SQLName & ";User Id=" & SPC_SQLID & "assword=" & SPC_SQLPass & ";"

­n³o¼Ë¼g
¬O¾Çµ{¦¡¦Ó¤£¬O­nµ{¦¡¡A¬O¶i¨Bªº°ò¦

TOP

        ÀR«ä¦Û¦b : ¦³¤ß´N¦³ºÖ¡A¦³Ä@´N¦³¤O¡A¦Û³yºÖ¥Ð¡A¦Û±oºÖ½t¡C
ªð¦^¦Cªí ¤W¤@¥DÃD