Click here to Skip to main content
15,891,033 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
VB
Private Sub RefreshStudentData()
        System.Windows.Forms.Cursor.Current = System.Windows.Forms.Cursors.WaitCursor
Dim connString As String = IIf(UCase(sSchoolName) = "SCHOOLA DRIVING SCHOOL", My.Settings.SCHOOLADATAConnectionString, My.Settings.SCHOOLBDATAConnectionString)
    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")
        With DataGridView1
            .DataSource = daEmp2
            .DataSource = dsEmp.Tables(0)
            .AutoGenerateColumns = True
            .Columns(0).Width = 60
            .Columns(1).Width = 190
            .Columns(0).HeaderText = "ID"
            .Columns(0).DefaultCellStyle.BackColor = Color.Black
            .Columns(0).DefaultCellStyle.ForeColor = Color.White
            .Refresh()
        End With

        System.Windows.Forms.Application.DoEvents()
    End Sub

The above fills the dataviewgrid with the selected database but the textboxes and navigator do not talk to the dataviewgrid. Is there an easy fix?

Thanking you in anticipation,
Trevor
Posted
Updated 10-Oct-10 6:15am
v2

Hello. What do these textboxes contain? Do they contain data from the datagridview? In what event do you call for these textboxes to fill with data?
If you are using this textboxes to edit the data in the database make sure you are using the correct connection string, with the sub RefreshStudentData() you have just filled the datagridview with the data maybe you have a sub that updates the database but the connection string within it is not from the database you are viewing. Could be a lot of reasons why it is not working with your textboxes.

I personally do not really trust these adapters, and binding sources, I like to handle my databases as I see fit. Lol.
 
Share this answer
 
Yes the text boxes contain data links to the binding sources respective fields. They are filled in the form load event Me.StudentInfoTableAdapter.Fill(Me.SCHOOLADataSet.StudentInfo)
 
Share this answer
 
Comments
Holc 10-Oct-10 18:11pm    
have you tried YourBindingSource.ResetBindings(False) or (True) if your metadata has changed (where YourBindingSource is the name of your binding source).
try inserting that on the end of RefreshStudentData() sub

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900