I was wondering whether anyone would be so kind as to answer a data question for me or refer me.
I have developed a student program where on a form I have placed 20 text boxes, a dataviewgrid, a navigator etc
I have two databases, one for each school.
I need to be able to switch between schools on this student page by selecting the school from the dropdown list.
I was wondering how I can change the bindingsource of this page to connect to schoola or schoolb depending on my selection.
Private Sub RefreshStudentData()
System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & SCHOOLDB & ";Persist Security Info=True"
Dim sQuery As String = "SELECT * FROM [StudentInfo] WHERE [CourseCode]=1 AND INACTIVE=-1 ORDER BY [LastName];"
Using connection As New OleDb.OleDbConnection(connString)
Dim command As New OleDb.OleDbCommand(sQuery, connection)
Dim daEmp2 As New OleDb.OleDbDataAdapter(command)
Dim dsEmp As New DataSet
daEmp2.Fill(dsEmp, "Surname")
DataGridView1.DataSource = daEmp2
DataGridView1.DataSource = dsEmp.Tables(0)
DataGridView1.Refresh()
End Using
Dim connString As String = IIf(UCase(sSchoolName) = "SCHOOL A", My.Settings.SCHOOLAConnectionString, My.Settings.SCHOOLBConnectionString)
Dim sQuery As String = "SELECT [StudentID],[Fullname] FROM [StudentInfo] WHERE [CourseCode]=1 AND INACTIVE=" & IIf(sGroup = "In-Active", True, False) & " ORDER BY [LastName];"
Using connection As New OleDb.OleDbConnection(connString)
Dim command As New OleDb.OleDbCommand(sQuery, connection)
Dim daEmp2 As New OleDb.OleDbDataAdapter(command)
Dim dsEmp As New DataSet
daEmp2.Fill(dsEmp, "StudentInfo")
DataGridView1.DataSource = daEmp2
DataGridView1.DataSource = dsEmp.Tables(0)
DataGridView1.AutoGenerateColumns = True
DataGridView1.Refresh()
End Using
System.Windows.Forms.Application.DoEvents()
End Sub
The above filles the dataviewgrid with the selected database but the textboxes and navigator do not talk to the dataviewgrid.
Is this an easy fix?
Thanking you in anticipation
Trevor