-
vb.net用户管理系统
Imports System.Data.SqlClient
Public Class Form1
Dim connstr As String = "Data Source=.;Initial Catalog=mydata;User ID=sa;Password=sa"
Dim txtusername As TextBox = New TextBox()
Dim txtpassword As TextBox = New TextBox()
WithEvents btnlogin As Button = New Button()
WithEvents dgv As DataGridView = New DataGridView()
Dim tc As TabControl = New TabControl()
Dim tp1 As TabPage = New TabPage("1")
Dim tp2 As TabPage = New TabPage("2")
Dim tp3 As TabPage = New TabPage("3")
Dim tp4 As TabPage = New TabPage("4")
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowAndShrink
Me.MaximizeBox = False
Me.AcceptButton = btnlogin
txtpassword.PasswordChar = "*"
btnlogin.Text = "登陆"
txtusername.Location = New Point(100, 100)
txtpassword.Location = New Point(100, 125)
btnlogin.Location = New Point(100, 150)
Me.Controls.Add(txtusername)
Me.Controls.Add(txtpassword)
Me.Controls.Add(btnlogin)
End Sub
Private Sub btnlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnlogin.Click
Dim username As String = Me.txtusername.Text.Trim()
Dim password As String = Me.txtpassword.Text.Trim()
If False Then
Return
End If
txtusername.Dispose()
txtpassword.Dispose()
btnlogin.Dispose()
Me.AutoSizeMode = Windows.Forms.AutoSizeMode.GrowOnly
Me.MaximizeBox = True
Me.WindowState = FormWindowState.Maximized
dgv.Dock = DockStyle.Fill
tp1.Controls.Add(dgv)
tc.Dock = DockStyle.Fill
tc.Controls.Add(tp1)
tc.Controls.Add(tp2)
tc.Controls.Add(tp3)
tc.Controls.Add(tp4)
Me.Controls.Add(tc)
Using conn As SqlClient.SqlConnection = New SqlClient.SqlConnection()
Using cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand()
Using sda As SqlClient.SqlDataAdapter = New SqlClient.SqlDataAdapter()
Using dt As DataTable = New DataTable
conn.ConnectionString = connstr
cmd.Connection = conn
cmd.CommandText = "select * from t_user"
sda.SelectCommand = cmd
sda.Fill(dt)
dgv.DataSource = dt
dgv.EditMode = DataGridViewEditMode.EditOnEnter
dgv.Columns(0).ReadOnly = True
End Using
End Using
End Using
End Using
End Sub
Private Sub dgv_CellValueChanged(ByVal sender As System.Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles dgv.CellValueChanged
Using conn As SqlClient.SqlConnection = New SqlClient.SqlConnection()
Using cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand()
Dim username As String = dgv.Rows(e.RowIndex).Cells(1).Value.ToString()
Dim gender As String = dgv.Rows(e.RowIndex).Cells(2).Value.ToString()
If Not gender.Equals("m") And Not gender.Equals("f") Then
MsgBox("性别必须是m或者f")
Return
End If
Dim birthday As String = dgv.Rows(e.RowIndex).Cells(3).Value.ToString()
If Not IsDate(birthday) Then
MsgBox("生日必须是日期类型")
Return
End If
Dim homeaddress As String = dgv.Rows(e.RowIndex).Cells(4).Value.ToString()
Dim idnumber As String = dgv.Rows(e.RowIndex).Cells(5).Value.ToString()
Dim id As String = dgv.Rows(e.RowIndex).Cells(0).Value.ToString()
conn.ConnectionString = connstr
cmd.Connection = conn
cmd.CommandText = "update t_user set username = @username, gender = @gender, birthday = @birthday, homeaddress = @homeaddress, idnumber = @idnumber where id = @id"
cmd.Parameters.AddWithValue("username", username)
cmd.Parameters.AddWithValue("gender", gender)
cmd.Parameters.AddWithValue("birthday", birthday)
cmd.Parameters.AddWithValue("homeaddress", homeaddress)
cmd.Parameters.AddWithValue("idnumber", idnumber)
cmd.Parameters.AddWithValue("id", id)
conn.Open()
cmd.ExecuteNonQuery()
End Using
End Using
End Sub
End Class
————————————————
版权声明:本文为CSDN博主「普通网友」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/eds124/article/details/84187484
栏目列表
最新更新
python爬虫及其可视化
使用python爬取豆瓣电影短评评论内容
nodejs爬虫
Python正则表达式完全指南
爬取豆瓣Top250图书数据
shp 地图文件批量添加字段
爬虫小试牛刀(爬取学校通知公告)
【python基础】函数-初识函数
【python基础】函数-返回值
HTTP请求:requests模块基础使用必知必会
SQL SERVER中递归
2个场景实例讲解GaussDB(DWS)基表统计信息估
常用的 SQL Server 关键字及其含义
动手分析SQL Server中的事务中使用的锁
openGauss内核分析:SQL by pass & 经典执行
一招教你如何高效批量导入与更新数据
天天写SQL,这些神奇的特性你知道吗?
openGauss内核分析:执行计划生成
[IM002]Navicat ODBC驱动器管理器 未发现数据
初入Sql Server 之 存储过程的简单使用
uniapp/H5 获取手机桌面壁纸 (静态壁纸)
[前端] DNS解析与优化
为什么在js中需要添加addEventListener()?
JS模块化系统
js通过Object.defineProperty() 定义和控制对象
这是目前我见过最好的跨域解决方案!
减少回流与重绘
减少回流与重绘
如何使用KrpanoToolJS在浏览器切图
performance.now() 与 Date.now() 对比