本文介绍了bindingsouce在运行时更改-2个数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道是不是有人愿意为我回答数据问题或推荐我.

我开发了一个学生程序,在该程序上,我放置了20个文本框,一个dataviewgrid,一个导航器等.我有两个数据库,每个学校一个.我需要能够通过从下拉列表中选择学校来在此学生页面上的学校之间进行切换.

我想知道如何根据我的选择更改此页面的绑定源以连接到schoola或schoolb.

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 = 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


上面用选定的数据库填充了dataviewgrid,但是文本框和导航器不与dataviewgrid对话.有简单的解决方法吗?

谢谢您的期待,
Trevor


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

推荐答案



这篇关于bindingsouce在运行时更改-2个数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 06:26