bindingsouce在运行时更改-2个数据库 [英] bindingsouce changes at runtime - 2 databases

查看:75
本文介绍了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

推荐答案

您好.这些文本框包含什么?它们是否包含来自datagridview的数据?在什么情况下,您要求这些文本框填充数据?
如果使用此文本框来编辑数据库中的数据,请确保使用正确的连接字符串,并使用RefreshStudentData()子句将数据填充到datagridview中,也许您有一个子集可以更新数据库,但是连接其中的字符串不是来自您正在查看的数据库.可能与文本框不兼容的原因很多.

我个人并不真正相信这些适配器和绑定源,我喜欢按我认为合适的方式处理数据库.大声笑.
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.


是的,文本框包含指向绑定源相应字段的数据链接.它们被填充为表单加载事件Me.StudentInfoTableAdapter.Fill(Me.SCHOOLADataSet.StudentInfo)
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)


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

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆