开发者

VB.NET Error: "The ConnectionString property has not been initialized."

Dim Current As String
Current = Directory.GetCurrentDirectory()
con.ConnectionString = "PROVIDER = Microsoft.Jet.OLEDB.4.0;Data Source = " & Current & "\SchoolMaticsDatabase.mdb"
con.Open()
TabSelect()
con.Close()

Private Sub TabSelect()
        Select Case TabControl1.SelectedIndex
            Case Is = 0
                TabDay = "Monday"
            Case Is = 1
                TabDay = "Tuesday"
            Case Is = 2
                TabDay = "Wednesday"
            Case Is = 3
                TabDay = "Thursday"
            Case Is = 4
                TabDay = "Friday"
            Case Is = 5
                TabDay = "Saturday"
            Case Is = 6
                TabDay = "Sunday"
        End Select
        ds.Clear()
        sql = "SELECT [Forename],[Surname],[Subject Speciality 1],[Subject Speciality 2],[Subject Speciality 3],[Subject Speciality 4],[Subject Speciality 5],[Subject Speciality 6]," & StartTime & "," & EndTime & ",[Spec1],[Spec2],[Spec3],[Spec4],[Spec5],[Spec6] FROM [Staff] WHERE " & TabDay & " LIKE 'T'"
        da = New OleDb.OleDbDataAdapter(sql, con)
        da.Fill(ds, "SchoolMaticsDatabase")
End Sub

da.fill(ds,"SchoolMaticsDatabase")>>> Errors occurs on this line of code.

If tab index is changed the sub TabSelect() is called also. One other thing is that the program checks the day of the week and correctly displays the tab corresponding to that day. On Monday开发者_如何学Python this code was working fine, as soon as it hit Tuesday this error cropped up.


Try passing conn as a parameter into the TabSelect() function. TabSelect(ByRef OleDbConnection conn) It could be an issue of scope since you are playing with global variables

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜