VB.net SQL数据库操作

Public Class Form_main

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim sqlcon As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\VB.mdb;Persist Security Info=False"
        Dim con As New System.Data.OleDb.OleDbConnection(sqlcon)
        con.Open()

        Try
            Dim sql_select As String = "select * from table1 order by id asc"
            Dim cmd_id As New System.Data.OleDb.OleDbCommand(sql_select, con)
            Dim drs As System.Data.OleDb.OleDbDataReader
            drs = cmd_id.ExecuteReader()
            drs.Read()
            Dim id As String
            id = drs.GetInt32(0)
            MessageBox.Show(id)
        Catch ex As Exception
            MessageBox.Show(ex.Message())
        End Try

        Try
            Dim sql1 As String = "insert into table1 values(1,'XC')"
            Dim cmd As New System.Data.OleDb.OleDbCommand(sql1, con)
            cmd.ExecuteReader()
        Catch ex As Exception
            MessageBox.Show("插入数据失败,ID号不能重复")
        End Try


        Dim sql As String = "select * from table1"
        Dim cmd2 As New System.Data.OleDb.OleDbCommand(sql, con)
        Dim dr As System.Data.OleDb.OleDbDataReader
        dr = cmd2.ExecuteReader()
        Dim str As String
        While dr.Read()
            str += dr.GetInt32(0).ToString()
            str += " "
            str += dr.GetString(1)
            str += "\\n"
        End While
        MessageBox.Show(str)

        dr.Close()
        con.Close()
    End Sub

    Private Sub TreeView1_MouseDoubleClick(ByVal sender As System.Object, ByVal e As System.Windows.Forms.MouseEventArgs)
        MessageBox.Show("OK")
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        PictureBox1.Refresh()
        Dim size As Drawing.Size
        size = PictureBox1.Size()
        PictureBox1.CreateGraphics().DrawLine(Pens.Blue, New Point(0, 0), New Point(size.Width / 3 * 2, size.Height / 3 * 2))
    End Sub

    Private Sub PictureBox1_SizeChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles PictureBox1.SizeChanged
        PictureBox1.Refresh()
        Dim size As Drawing.Size
        size = PictureBox1.Size()
        Dim pen As New System.Drawing.Pen(System.Drawing.Color.Blue, 1)
        pen.DashStyle = System.Drawing.Drawing2D.DashStyle.Dash
        PictureBox1.CreateGraphics().DrawLine(pen, New Point(0, 0), New Point(size.Width / 3 * 2, size.Height / 3 * 2))
        PictureBox1.CreateGraphics.DrawLine(pen, New Point(0, 10), New Point(100, 10))
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim str As String
        str = TextBox1.Text()
        TextBox1.Text() = "aec"
        MessageBox.Show(str)
    End Sub

    Private Sub Form_main_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TreeView1.Nodes.Add("PA")
        TreeView1.Nodes(0).Nodes.Add("P")
        TreeView1.Nodes(0).Nodes.Add("A")
    End Sub
End Class
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值