zoukankan      html  css  js  c++  java
  • 添加,修改,删除

    前面声明

    Imports System.Data

    Imports System.Data.OleDb

    ――――――――――――――――

    Private ds As DataSet = New DataSet

    Private ds1 As DataSet = New DataSet

    Private sqlStr As String

    Private strcon As String = "Provider=SQLOLEDB.1;Data Source=(local);

            Initial Catalog=数据库名;User ID=sa;Password=sa"

    Public DBcon As New OleDbConnection(strcon)

    ――――――――――――――――

    Private Sub DBView()

    DBcon.Open() sqlStr = "select * from 表"

    Dim adt As New OleDbDataAdapter(sqlStr, DBcon)

    ds.Clear()

    adt.Fill(ds)

    Me.DataGrid1.DataSource = ds.Tables(0)

    DBcon.Close()

    End Sub

    ――――――――――――――――

     

    添加:

    Try

       Dim comid, comname, danwei, comtype As String

     

       comid = Trim(Me.TextBox1.Text)

       comname = Me.TextBox2.Text

       danwei = Trim(Me.ComboBox1.SelectedItem)

       comtype = Trim(Me.ComboBox2.SelectedItem)

       DBcon.Open()

       If comname = "" Then

           MsgBox("comname can't be Empty!", MsgBoxStyle.Critical, Me.Text)

           Return

       End If

       If danwei = "" Then

           MsgBox("danwei can't be Empty!", MsgBoxStyle.Critical, Me.Text)

           Return

       End If

       If comtype = "" Then

           MsgBox("comtype can't be Empty!", MsgBoxStyle.Critical, Me.Text)

           Return

       End If

     

       if Me.CheckBox1.Checked = False Then

            Dim sqlStr As String = "insert into TMMCom values ('" & Trim(comid) & "','" & comname & "','" & danwei & "','" & comtype & "',0)"

            Dim adt As New OleDbDataAdapter(sqlStr, DBcon)

            ds.Clear()

            adt.Fill(ds)

            DBcon.Close()

            DBView()

       Else

            Dim sqlStr As String = "insert into TMMCom values ('" & Trim(comid) & "','" & comname & "','" & danwei & "','" & comtype & "',1)"

            Dim adt As New OleDbDataAdapter(sqlStr, DBcon)

            ds.Clear()

            adt.Fill(ds)

            DBcon.Close()

            DBView()

        End If

     Catch ex As Exception

         MsgBox("comid can't be Repeat!", MsgBoxStyle.Critical, Me.Text)

    End Try

     

    修改:

    Dim comid, comname, danwei, comtype As String

    comid = Trim(Me.TextBox1.Text)

        comname = Me.TextBox2.Text

        danwei = Trim(Me.ComboBox1.SelectedItem)

        comtype = Trim(Me.ComboBox2.SelectedItem)

    If comname = "" Then

        MsgBox("comname can't be Empty!", MsgBoxStyle.Critical, Me.Text)

    Return

    End if

    If danwei = "" Then

        MsgBox("danwei can't be Empty!", MsgBoxStyle.Critical, Me.Text)

        Return

    End if

    If comtype = "" Then

        MsgBox("comtype can't be Empty!", MsgBoxStyle.Critical, Me.Text)

        Return

    End if

     

    DBcon.Open()

        Dim sqlStr As String = "update TMMCom set cComName='" & comname & "',cDanwei='" & danwei & "',cComType='" & comtype & "'where iComID ='" & comid & "'"

       Dim adt As New OleDbDataAdapter(sqlStr, DBcon)

        ds.Clear()

        adt.Fill(ds)

        DBcon.Close()

        DBView()

     

    删除:

    Dim comid As Int32

    comid = CInt(Me.TextBox1.Text)

     

    DBcon.Open()

    Dim sqlStr As String = "update TMMCom set cComName='',cDanwei='',cComType=''where iComID =" & comid & ""

    Dim adt As New OleDbDataAdapter(sqlStr, DBcon)

    ds.Clear()

    adt.Fill(ds)

    DBcon.Close()

    DBView()

  • 相关阅读:
    (转)要在自己感兴趣的领域成为专家,要经过一万小时训练
    (学习日记)数据结构第一章中life游戏开发的学习记录
    (转)响应式Web设计是大势所趋还是时代的产物
    (学习日记)裘宗燕:C/C++ 语言中的表达式求值
    (转)如果你喜欢编程 给想做程序员的人的7个建议
    NHibernate 中删除数据的几种方法
    如何避免在安装SQL SERVER 2008时,出现Rule “Previous releases of Microsoft Visual Studio 2008″ failed.
    【转】A brief overview of Ncqrs
    爱博图微博图片批量下载小工具
    解释用Q号算出你的年龄的“奥妙”。。。
  • 原文地址:https://www.cnblogs.com/sishierfei/p/1610382.html
Copyright © 2011-2022 走看看