VB.net SQL数据库操作

前端之家收集整理的这篇文章主要介绍了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,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 原文链接:https://www.f2er.com/vb/258936.html

猜你在找的VB相关文章