加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

VB.net SQL数据库操作

发布时间:2020-12-17 08:15:27 所属栏目:百科 来源:网络整理
导读: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" Di
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,size.Height / 3 * 2)) PictureBox1.CreateGraphics.DrawLine(pen,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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读