| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1241 人关注过本帖
标题:数据绑定后只能显示修改后的数据?
只看楼主 加入收藏
yxh1111
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-12-21
收藏
 问题点数:0 回复次数:2 
数据绑定后只能显示修改后的数据?
数据绑定后只能显示修改后的数据?


2005

问题:

新建 添加 用户后  不能显示所有的数据而只能显示修改后的数据

WindowsApplication1.rar (78.83 KB)
搜索更多相关主题的帖子: 绑定 数据 
2008-12-13 15:59
bygg
Rank: 16Rank: 16Rank: 16Rank: 16
来 自:乖乖的心中
等 级:版主
威 望:241
帖 子:13555
专家分:3076
注 册:2006-10-23
收藏
得分:0 
你有没有重新进行数据的读取绑定?
你把关键的代码发出来就可以了,不要把所有的都发出来....下载也比较麻烦

飘过~~
2008-12-13 18:41
yxh1111
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2007-12-21
收藏
得分:0 
代码~~~~

Imports System.Data.OleDb
Module Commonmodule
Public mydap As OleDbDataAdapter
    '建立DataSet对象
    Public mydataset As DataSet = New DataSet
    '定义一个表对象
    Public mytable As DataTable
    '定义一个行对象
    Public myrow As DataRow
    '定义一个OleDbCommandBuilder对象,用于协调DataSet的更改所自动生成的单表命令
    Public mycmdbuildder As OleDbCommandBuilder
    Public Function SQLOpera(ByVal str As String, ByVal table As String) 'str参数为查询语句,table为所要执行的表
        Try
            '定义一个存储当前行数的变量
            Dim row As Integer = 0
            '定义一个执行SQL命令的字符串变量
            Dim Selectstring As String
            Selectstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="
            '使用相对路径
            Selectstring = Selectstring & Application.StartupPath() & "\Data\mydb.mdb"
            mydap = New OleDbDataAdapter(str, Selectstring)
            '清除数据集的所有表
            mydataset.Clear()
            mydataset.Tables.Clear()
            '填充数据集
            mydap.Fill(mydataset, table)
            '获取数据集中的表
            mytable = mydataset.Tables.Item(0)
            myrow = mytable.Rows.Item(row)
        Catch ex As Exception
        End Try
        Return Nothing
    End Function
End Module

user窗体
Public Class user
    Private Sub ShowCurrentPosition()
        Me.TextBox3.Text = Me.BindingContext(Commonmodule.mydataset, "管理员表").Position + 1 & " of " & Me.BindingContext(Commonmodule.mydataset, "管理员表").Count
        '显示当前数据绑定的管理对象的数据位置
    End Sub
    Private Sub bangding()

        Dim tablename As String = "管理员表"
        Dim strr As String
        strr = "select 用户,密码,身份,前台营业,外卖服务,酒宴预定,员工管理 from 管理员表"
        Commonmodule.SQLOpera(strr, tablename)
        Try
            Me.TextBox1.DataBindings.Clear()
            Me.TextBox2.DataBindings.Clear()
            ()
            Me.CheckBox1.DataBindings.Clear()
            Me.CheckBox2.DataBindings.Clear()
            Me.CheckBox3.DataBindings.Clear()
            Me.CheckBox4.DataBindings.Clear()
            Me.TextBox1.DataBindings.Add("text", Commonmodule.mydataset, "管理员表.用户")
            Me.TextBox2.DataBindings.Add("text", Commonmodule.mydataset, "管理员表.密码")
            ("text", Commonmodule.mydataset, "管理员表.身份")
            Me.CheckBox1.DataBindings.Add("Checked", Commonmodule.mydataset, "管理员表.前台营业")
            Me.CheckBox2.DataBindings.Add("Checked", Commonmodule.mydataset, "管理员表.外卖服务")
            Me.CheckBox3.DataBindings.Add("Checked", Commonmodule.mydataset, "管理员表.酒宴预定")
            Me.CheckBox4.DataBindings.Add("Checked", Commonmodule.mydataset, "管理员表.员工管理")
            ShowCurrentPosition()
        Catch ex As Exception
            MsgBox("该学号的注册信息不存在!", MsgBoxStyle.Exclamation + MsgBoxStyle.OkOnly, "Information...")
        End Try
    End Sub

    Private Sub QXbangding()

        Me.TextBox1.DataBindings.Clear()
        Me.TextBox2.DataBindings.Clear()
        ()
        Me.CheckBox1.DataBindings.Clear()
        Me.CheckBox2.DataBindings.Clear()
        Me.CheckBox3.DataBindings.Clear()
        Me.CheckBox4.DataBindings.Clear()
   
    End Sub

    Private Sub user_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        bangding()
    End Sub

    Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        Me.BindingContext(Commonmodule.mydataset, "管理员表").Position += 1
        ShowCurrentPosition()
    End Sub

    Private Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        Me.BindingContext(Commonmodule.mydataset, "管理员表").Position -= 1
        ShowCurrentPosition()
    End Sub

    Private Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
        Me.BindingContext(Commonmodule.mydataset, "管理员表").Position = 0
        ShowCurrentPosition()
    End Sub

    Private Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
        Me.BindingContext(Commonmodule.mydataset, "管理员表").Position = Me.BindingContext(Commonmodule.mydataset, "管理员表").Count - 1
        ShowCurrentPosition()
    End Sub

    Private Sub btnNew_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNew.Click
        QXbangding()
        TextBox1.Text = ""
        TextBox2.Text = ""
        ComboBox1.Text = "超级管理员"
        CheckBox1.Checked = False
        CheckBox2.Checked = False
        CheckBox3.Checked = False
        CheckBox4.Checked = False
        btnDelete.Enabled = False
        btnSearch.Enabled = False
        btnAdd.Enabled = True
        '  GroupBox3.Enabled = False
    End Sub

    Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
        Dim tablename As String = "管理员表"
        Dim strr As String
        strr = "select * from 管理员表"
        Try
            '传递参数,执行公共模块的SQLOpera函数
            Commonmodule.SQLOpera(strr, tablename)
            '建立一个新的行对象,以便在数据集中插入新行
            Dim addrow As DataRow = Commonmodule.mytable.NewRow
            '将信息添加进新行中
            addrow.Item(0) = Trim(TextBox1.Text)
            addrow.Item(1) = Trim(TextBox2.Text)
            addrow.Item(2) = Trim(ComboBox1.Text)
            addrow.Item(3) = CheckBox1.Checked
            addrow.Item(4) = CheckBox2.Checked
            addrow.Item(5) = CheckBox3.Checked
            addrow.Item(6) = CheckBox4.Checked

            '将新行添加进表中
            mytable.Rows.Add(addrow)
            '使用OleDbCommandBuilder对象自动生成SQL命令
            Commonmodule.mycmdbuildder = New OleDb.OleDbCommandBuilder(Commonmodule.mydap)
            '更新数据库
            Commonmodule.mydap.Update(Commonmodule.mydataset, tablename)
            '使用对话框提示用户添加成功
            MsgBox("添加成功!", MsgBoxStyle.OkOnly + MsgBoxStyle.Information, "Information...")
            btnDelete.Enabled = True
            btnSearch.Enabled = True
            btnAdd.Enabled = False

            'GroupBox3.Enabled = True
            Dim tablenamea As String = "员工管理"
            Dim strra As String
            strra = "select 员工编码,真实姓名,性别 from 员工管理"
            Commonmodule.SQLOpera(strra, tablenamea)
            Me.TextBox1.DataBindings.Clear()
            Me.TextBox2.DataBindings.Clear()
            ()
            Me.CheckBox1.DataBindings.Clear()
            Me.CheckBox2.DataBindings.Clear()
            Me.CheckBox3.DataBindings.Clear()
            Me.CheckBox4.DataBindings.Clear()
            Me.TextBox1.DataBindings.Add(New System.Windows.Forms.Binding("text", Commonmodule.mydataset, "员工管理.员工编码"))
            Me.TextBox2.DataBindings.Add(New System.Windows.Forms.Binding("text", Commonmodule.mydataset, "员工管理.真实姓名"))
            (New System.Windows.Forms.Binding("text", Commonmodule.mydataset, "员工管理.性别"))
            '    Me.CheckBox1.DataBindings.Add(New System.Windows.Forms.Binding("Checked", Commonmodule.mydataset, "管理员表.前台营业"))
            '     Me.CheckBox2.DataBindings.Add(New System.Windows.Forms.Binding("Checked", Commonmodule.mydataset, "管理员表.外卖服务"))
            '    Me.CheckBox3.DataBindings.Add(New System.Windows.Forms.Binding("Checked", Commonmodule.mydataset, "管理员表.酒宴预定"))
            '    Me.CheckBox4.DataBindings.Add(New System.Windows.Forms.Binding("Checked", Commonmodule.mydataset, "管理员表.员工管理"))
            ShowCurrentPosition()


        Catch ex As Exception
            MsgBox(Err.Description, MsgBoxStyle.OkOnly + MsgBoxStyle.Exclamation, "Information...")
        End Try

    End Sub
End Class
2008-12-13 21:26
快速回复:数据绑定后只能显示修改后的数据?
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.024182 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved