關於如何編寫 編輯、添加、刪除、查詢的一系列功能?

LiloZhu 2003-10-16 11:26:41
我初步制定是這樣的:

ID_________(TEXTBOX) USER__________(TEXTBOX) KIND________(COMBOX)

DATE_______ MEMO__________ edit (Button)
add (Button)
find (Button)
delete(Button)

datagrid:
_______________________________________________
| ID | USER | KIND | DATE |MEMO |
_______________________________________________

_______________________________________________

_______________________________________________

我現在只能把數據庫中的數據取出來顯示於 datagrid 中,其它功能還不知如何去做:請大家幫忙,

我如何完成鼠標點擊datagrid的數據的那一條記錄正好與上面控件(textbox,combox...)正好跟著轉變,也就是如果我點擊上面的 add 添加按鈕那此textbox,combxo中輸入數據,會得到要個操作,一個會顯示於datagrid中,另一個會將輸入有信息存入數據庫中。
find (BUTTON)
edit (BUTTON)
delete (BUTTON)

也應如此,各位大哥,你們可做過這樣的例子,可何提供給小弟參考一下,小弟不勝感激!!!

我的E-MAIL: wzhu@grandion.com
qq:247893192
msn:zw_xrain@hotmail.com
...全文
67 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
tangyifei 2003-10-16
  • 打赏
  • 举报
回复

'有什么问题可以找我,我的QQ:106171791
Private cn As New OleDbConnection
Private da As OleDbDataAdapter
Private ds As New DataSet
Private dt As New DataTable
Private isEdit As Boolean = False

Private Sub frmMain_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
CreateDataSet()
InitializeBindings()
BindClassGrid()
UpdateViewState()
End Sub

Private Sub CreateDataSet()

If cn.State = ConnectionState.Open = True Then cn.Close()
Dim str As String = "Data Source=" & Application.StartupPath & "\User.mdb"
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Jet OLEDB:Database Password=fireball;" & str
cn.Open()
da = New OleDbDataAdapter("Select * From Users", cn)
Dim oCommandBuilder As New OleDbCommandBuilder(da)
oCommandBuilder.GetInsertCommand()
oCommandBuilder.GetDeleteCommand()
oCommandBuilder.GetUpdateCommand()
da.Fill(ds, "Users")
cn.Close()
dt = ds.Tables("Users")

End Sub

Private Sub InitializeBindings()
txtID.DataBindings.Add("text", dt, "IDS")
txtUser.DataBindings.Add("text", dt, "Users")
txtKind.DataBindings.Add("text", dt, "Kinds")
txtDate.DataBindings.Add("text", dt, "Dates")
txtMemo.DataBindings.Add("text", dt, "Memos")
End Sub

'-----添加
Private Sub cmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdAdd.Click
Me.BindingContext(dt).EndCurrentEdit()
Me.BindingContext(dt).AddNew()
isEdit = True
UpdateViewState()
End Sub

'修改
Private Sub cmdEdit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdEdit.Click
isEdit = True
UpdateViewState()
End Sub

'-----删除
Private Sub cmdDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDelete.Click

Me.BindingContext(dt).EndCurrentEdit()
dt.Rows(Me.BindingContext(dt).Position).Delete()
da.Update(dt)
End Sub

'---保存
Private Sub cmdSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSave.Click

Try
Me.BindingContext(dt).EndCurrentEdit()
da.Update(dt)
isEdit = False
UpdateViewState()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
End Try
End Sub

'--取消
Private Sub cmdCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdCancel.Click
Me.BindingContext(dt).EndCurrentEdit()
isEdit = False
UpdateViewState()
End Sub

Private Sub UpdateViewState()
If isEdit Then
cmdAdd.Enabled = False
cmdEdit.Enabled = False
cmdDelete.Enabled = False
cmdSave.Enabled = True
cmdCancel.Enabled = True
Else
cmdAdd.Enabled = True
cmdEdit.Enabled = True
cmdDelete.Enabled = True
cmdSave.Enabled = False
cmdCancel.Enabled = False
End If
End Sub

'-------绑定栅格控件的过程
Private Sub BindClassGrid()
With dgUser
.CaptionText = "User"
.DataSource = dt
End With

dgUser.TableStyles.Clear()

Dim grdTableStyle1 As New DataGridTableStyle

With grdTableStyle1
.MappingName = dt.TableName

End With

Dim grdColStyle1 As New DataGridTextBoxColumn

With grdColStyle1
.MappingName = "IDS"
.HeaderText = "ID"
.Width = 80
End With

Dim grdColStyle2 As New DataGridTextBoxColumn

With grdColStyle2
.MappingName = "Users"
.HeaderText = "User"
.Width = 80
End With

Dim grdColStyle3 As New DataGridTextBoxColumn

With grdColStyle3
.MappingName = "Kinds"
.HeaderText = "Kind"
.Width = 80
End With

Dim grdColStyle4 As New DataGridTextBoxColumn

With grdColStyle4
.MappingName = "Dates"
.HeaderText = "Date"
.Width = 80
End With

Dim grdColStyle5 As New DataGridTextBoxColumn

With grdColStyle5
.MappingName = "Memos"
.HeaderText = "Memo"
.Width = 80
End With

grdTableStyle1.GridColumnStyles.AddRange(New DataGridColumnStyle() _
{grdColStyle1, grdColStyle2, grdColStyle3, grdColStyle4, grdColStyle5})

dgUser.TableStyles.Add(grdTableStyle1)
End Sub
1,项目功能:(1)房屋信息查询:主要实现租房信息的查看功能。用户可以查看房屋信息,并选择自己比较想要租的房屋。(2)租房服务:对用户提供租房服务信息的查看。用户可以查询到该系统所提供的所有租房服务信息。(3)金牌经纪人:主要对经纪人信息进行查看。 用户可以查询经纪人信息,并选择自己满意的经纪人为自己服务。(4)百科知识:主要实现对百科知识的查看功能。用户可以查询到和租房相关的百科知识,增加对二手房租赁的相关了解。(5)个人信息:主要实现个人信息的查询与修改功能。用户可以查询到个人信息,并对个人信息的更新进行修改操作。(6)用户列表:主要实现用户信息的添加,修改,删除和查看功能。管理员可以查看用户列表,并对列表信息后面得编辑按钮进入编辑页面,在编辑页面把修改内容修改完后,点击提交按钮完成修改操作,用户也可以根据列表中的删除按钮把对应信息删除,通过点击添加按钮,进入添加页面,填入添加的信息,完成添加。(7)百科列表:主要实现百科知识的添加,删除,修改和查看功能。管理员可以查看百科列表,并对列表信息后面得编辑按钮进入编辑页面,在编辑页面把修改内容修改完后,点击提交按钮完成修改操作,用户也可以根据列表中的删除按钮把对应信息删除,通过点击添加按钮,进入添加页面,填入添加的信息,完成添加。(8)预约列表:主要实现预约信息的添加,删除,修改和查看功能。管理员可以查看用户的预约列表,并对列表信息后面得编辑按钮进入编辑页面,在编辑页面把修改内容修改完后,点击提交按钮完成修改操作,用户也可以根据列表中的删除按钮把对应信息删除,通过点击添加按钮,进入添加页面,填入添加的信息,完成添加。(9)房源列表:主要实现房源信息的添加,修改,删除和查看功能。管理员可以查看房源信息列表,并对列表信息后面得编辑按钮进入编辑页面,在编辑页面把修改内容修改完后,点击提交按钮完成修改操作,用户也可以根据列表中的删除按钮把对应信息删除,通过点击添加按钮,进入添加页面,填入添加的信息,完成添加。(10)评论列表:主要实现评论信息的添加,修改,删除和查看功能。管理员可以查看评论信息列表,并对列表信息后面得编辑按钮进入编辑页面,在编辑页面把修改内容修改完后,点击提交按钮完成修改操作,用户也可以根据列表中的删除按钮把对应信息删除,通过点击添加按钮,进入添加页面,填入添加的信息,完成添加。(11)主要实现对房源信息进行统计分析。管理员可以对房源信息进行统计并也图表形式展现。      适合做毕业设计参考项目。2,涉及技术:SSM框架,Tomcat3,开发环境:IDEA,MySQL数据库4,讲解方式:从环境安装,项目搭建,以及项目介绍等进行讲解5,包含资料:项目源码(含数据库文件),环境安装包,项目文档。

16,553

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧