| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1086 人关注过本帖
标题:数据库与listbox的绑定问题
取消只看楼主 加入收藏
魔的天使之翼
Rank: 1
等 级:新手上路
帖 子:16
专家分:0
注 册:2007-9-21
收藏
 问题点数:0 回复次数:0 
数据库与listbox的绑定问题
'保存
    Private Sub MenuItem9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem9.Click
        Dim s As String, name As String
        If txttitle.Text = "" Then
            MsgBox("请输入日记标题", MsgBoxStyle.Exclamation Or MsgBoxStyle.OKOnly, "标题")
        Else
            name = txttitle.Text & ".txt"
            s = Application.StartupPath() + "\" & txttitle.Text & ".txt"
            RichTextBox1.SaveFile(s, RichTextBoxStreamType.PlainText)
            MsgBox("保存成功", MsgBoxStyle.OKOnly, "保存文件")

            Dim connstr, insertcmd As String
            Dim selectComd As String = "select * from riji"
            connstr = "provider=microsoft.jet.oledb.4.0;data source=rijititle.mdb"
            insertcmd = "insert into riji(title) values('" & getsqlstr(txttitle.Text) & " ')"

            Dim conn As OleDbConnection, myadapter As OleDbDataAdapter
            Dim mydataset As New DataSet
            Dim cmd As OleDbCommand
            conn = New OleDbConnection(connstr)
            conn.Open()
            cmd = New OleDbCommand(insertcmd, conn)
            cmd.ExecuteNonQuery()
            conn.Close()

            ListBox1.DataSource = mydataset.Tables("riji")
            Me.ListBox1.DisplayMember = "title"


        End If
    End Sub


'点击日志名字进入查看内容
    Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
        lbltitle.Text = ListBox1.SelectedItem
        Label1.Visible = False
        txttitle.Visible = False
        RichTextBox1.Visible = True
        ListBox1.Visible = False
        MenuItem1.Visible = True
        MenuItem5.Visible = True
        MenuItem8.Visible = True
        MenuItem9.Visible = True
        MenuItem10.Visible = True
        Button2.Visible = False
        btnselect.Visible = True
        lbltitle.Visible = True
        btndel.Visible = False
        btnsave.Visible = False
        RichTextBox1.LoadFile(Application.StartupPath + "\" + txttitle.Text + ".txt", RichTextBoxStreamType.PlainText)

    End Sub


我把listbox的displaymember 绑定数据库,点击listbox的一项,然后把这项的内容给label.text  结果
lbltitle.Text = ListBox1.SelectedItem  出错,说datarowview 不能强制转化为string 类型。要怎么循环读数据库,并把
一个字段的内容add到listbox 控件里面。
搜索更多相关主题的帖子: 数据库 绑定 listbox 
2007-12-11 17:00
快速回复:数据库与listbox的绑定问题
数据加载中...
 
   



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

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