0

任何人都可以将此代码更改为SqlConnection

Dim Db As ADODB.Connection
Dim rs As ADODB.Recordset

Set Db = New ADODB.Connection
Db.ConnectionString = GetConnectString & AppPath & "schedule.mdb"
Call Db.Open
Set rs = New ADODB.Recordset
Set rs = Db.Execute("select * from tbl_Schedule where StartDate = #1/1/2002#")

While Not rs.EOF
Call Me.Schedule1.ScheduleItems.Add("", #1/1/2002#, rs!StartTime, _ 
rs!Length, rs!Description, "")
Call rs.MoveNext
Wend
4

1 回答 1

0

请找到下面的代码片段,它可以帮助您从 sql 数据库中获取数据。您可以使用您的值更改脚本。导入 System.Data.SqlClient 命名空间以使用 SqlConnection

Dim connection As New SqlConnection("Server=.\sqlexpress;Integrated   security=sspi;database=Automation")
Dim query As String = "Select * from Heads"
If connection.State = ConnectionState.Closed Then connection.Open()
   Using cmd As New SqlCommand(query, connection)
        Dim reader As SqlDataReader = cmd.ExecuteReader
        While reader.Read
            ListBox1.Items.Add(reader("HeadName").ToString)
        End While
        reader.Close()
        connection.Close()
   End Using
于 2013-07-06T20:28:43.443 回答