设为首页收藏本站Access中国

Office中国论坛/Access中国论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

返回列表 发新帖
查看: 2792|回复: 6

【VB.NET小品】Access与VB.NET结合示例 第三课

[复制链接]
发表于 2013-6-26 14:40:27 | 显示全部楼层 |阅读模式
本帖最后由 todaynew 于 2013-6-26 14:43 编辑

第三课示例文件:

上一课

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x

本帖被以下淘专辑推荐:

 楼主| 发表于 2013-6-26 14:41:00 | 显示全部楼层
本帖最后由 todaynew 于 2013-6-26 14:43 编辑

  第九节:
  27、在Form1.vb窗口中,选中btn新增控件,然后选中Click事件,系统自动产生该事件。
  28、在该事件中写如下代码:
         '清空
         If String.IsNullOrEmpty(txt药品ID.Text) = False Then
             txt药品ID.Text = ""
             txt药品名称.Text = ""
             txt药品名称简拼.Text = ""
             txt规格.Text = ""
             txt处方单位.Text = ""
             txt单价.Text = "0"
             txt有效.Text = "True"
             Exit Sub
         End If
         '新增
         Using ad As 药品收费项目TableAdapter = New 药品收费项目TableAdapter()
             Dim n As Integer = ad.Insert(txt药品类别.Text, _
                                          txt药品名称.Text, _
                                          txt药品名称简拼.Text, _
                                          txt规格.Text, _
                                          txt处方单位.Text, _
                                          CInt(txt单价.Text), _
                                          CBool(txt有效.Text))

            If n > 0 Then
                 Me.药品收费项目TableAdapter.FillBy药品类别(Me.药品DataSet.药品收费项目,

ComboBox1.Text)
                 '跳转到最后一条记录
                 DataGridView1.CurrentCell = DataGridView1.Rows(DataGridView1.RowCount -

2).Cells(0)
                 txt药品ID.Text = CStr(DataGridView1.CurrentCell.Value)
             Else
                 MsgBox("新增失败!")
             End If
         End Using

  29、生成并运行程序,查看效果



 楼主| 发表于 2013-6-26 14:41:25 | 显示全部楼层
本帖最后由 todaynew 于 2013-6-26 14:44 编辑

  第十节:
  30、在Form1.vb窗口中,选中btn修改控件,然后选中Click事件,系统自动产生该事件。
  31、在该事件中写如下代码:
         
        If String.IsNullOrEmpty(txt药品ID.Text) Then Exit Sub
         '更新
         Dim rowindex As Integer = DataGridView1.CurrentRow.Index
         Using ad As New 药品收费项目TableAdapter()
             Dim n As Integer = ad.UpdateBy药品ID(txt药品类别.Text, _
                                          txt药品名称.Text, _
                                          txt药品名称简拼.Text, _
                                          txt规格.Text, _
                                          txt处方单位.Text, _
                                          CInt(txt单价.Text), _
                                          CBool(txt有效.Text), CInt(txt药品ID.Text))
             If n > 0 Then
                 Me.药品收费项目TableAdapter.FillBy药品类别(Me.药品DataSet.药品收费项目,

ComboBox1.Text)
                 '跳转到修改记录
                 DataGridView1.CurrentCell = DataGridView1.Rows(rowindex).Cells(0)
             Else
                 MsgBox("修改失败!")
             End If
         End Using

  32、生成并运行程序,查看效果。



 楼主| 发表于 2013-6-26 14:41:42 | 显示全部楼层
本帖最后由 todaynew 于 2013-6-26 14:45 编辑

  33、在Form1.vb窗口中,选中btn删除控件,然后选中Click事件,系统自动产生该事件。
  34、在该事件中写如下代码:
         
        If String.IsNullOrEmpty(txt药品ID.Text) Then Exit Sub
         '删除
         Using ad As New 药品收费项目TableAdapter()
             Dim n As Integer = ad.DeleteBy药品ID(CInt(txt药品ID.Text))
             If n > 0 Then
                 Me.药品收费项目TableAdapter.FillBy药品类别(Me.药品DataSet.药品收费项目,

ComboBox1.Text)
                 txt药品ID.Text = ""
                 txt药品名称.Text = ""
                 txt药品名称简拼.Text = ""
                 txt规格.Text = ""
                 txt处方单位.Text = ""
                 txt单价.Text = "0"
                 txt有效.Text = "True"
             Else
                 MsgBox("删除失败!")
             End If
         End Using

  35、生成并运行程序,查看效果。



点击这里给我发消息

发表于 2013-6-26 16:07:14 | 显示全部楼层
谢谢分享了

点击这里给我发消息

发表于 2013-6-26 18:19:50 | 显示全部楼层
佩服,工作量好大!

顶!

点击这里给我发消息

发表于 2019-5-18 08:08:52 | 显示全部楼层
太强大了
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-3-29 06:01 , Processed in 0.092896 second(s), 34 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表