Office中国论坛/Access中国论坛

标题: 【VB.NET小品】Access与VB.NET结合示例 第三课 [打印本页]

作者: todaynew    时间: 2013-6-26 14:40
标题: 【VB.NET小品】Access与VB.NET结合示例 第三课
本帖最后由 todaynew 于 2013-6-26 14:43 编辑

第三课示例文件:[attach]52031[/attach]

上一课


作者: todaynew    时间: 2013-6-26 14:41
本帖最后由 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、生成并运行程序,查看效果




作者: todaynew    时间: 2013-6-26 14:41
本帖最后由 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、生成并运行程序,查看效果。




作者: todaynew    时间: 2013-6-26 14:41
本帖最后由 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、生成并运行程序,查看效果。




作者: admin    时间: 2013-6-26 16:07
谢谢分享了
作者: zhuyiwen    时间: 2013-6-26 18:19
佩服,工作量好大!

顶!
作者: boon    时间: 2019-5-18 08:08
太强大了




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3