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()

  • 相关阅读:
    P3469 [POI2008]BLO-Blockade
    洛谷P2342 叠积木
    洛谷 P1197 [JSOI2008]星球大战
    洛谷P1967 货车运输
    洛谷P2812校园网络【Network of Schools加强版】
    洛谷P3003 苹果交货Apple Delivery
    luogu Eat the Trees
    插头DP模板
    [NOIP2017] 宝藏
    LOJ6268拆分数
  • 原文地址:https://www.cnblogs.com/sishierfei/p/1610382.html
Copyright © 2011-2022 走看看