VS2019使用VB.Net设计一个窗体连接SQL server数据库中学生表的内容并显示,实现数据绑定,表格内容前后查看
2020-07-14 06:29
483 查看
先看一下效果图:文本框用label控件,按钮用button控件,显示用框TextBox控件,(Name)可以自己修改
建立一个学生表名字为Student
双击窗体进入代码界面,最顶上输入:
Imports System.Data.SqlClient '导入命名空间
窗体的代码:
Public Class UserControl1 '系统自动生成的 Dim ds As DataSet = New DataSet '建立类中可访问数据对象ds,且为全局变量 Public mybind As BindingManagerBase '绑定对象的定义,名为mybind Private Sub UserControl1_Load(sender As Object, e As EventArgs) Handles MyBase.Load '系统自动生成的 Dim strconn As String = "Server=localhost;Database=学生成绩管理系统;Integrated Security=SSPI" '建立一个连接字符串strconn Dim strsql As String = "select Snum,Sname,Ssex,Sbirth,Sdept,province from Student" '建立一个查询字符串strsql Dim myconnect As SqlConnection = New SqlConnection(strconn) '建立一个数据连接myconnect Dim mycommand As SqlDataAdapter = New SqlDataAdapter(strsql, myconnect) '建立一个数据适配器mycommand对数据执行sql指令 mycommand.Fill(ds, "Student")'指定绑定的数据源 mybind = Me.BindingContext(ds, "Student") 'TextBox控件的Text属性绑定至数据集ds内的Student表 TextBoxSnum.DataBindings.Add("Text", ds, "Student.Snum") TextBoxSname.DataBindings.Add("Text", ds, "Student.Sname") TextBoxSsex.DataBindings.Add("Text", ds, "Student.Ssex") TextBoxSdept.DataBindings.Add("Text", ds, "Student.Sdept") TextBoxSbirth.DataBindings.Add("Text", ds, "Student.Sbirth") TextBoxprovince.DataBindings.Add("Text", ds, "Student.province") End Sub
双击"第一条"按钮
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click mybind.Position = 0 '跳转到第一条 End Sub
双击"上一条"按钮
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click If mybind.Position > 0 Then mybind.Position -= 1 End If End Sub
双击"下一条"按钮
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click If mybind.Position > 0 Then mybind.Position += 1 End If End Sub
双击"最后一条"按钮
Private Sub Button4_Click(sender As Object, e As EventArgs) Handles Button4.Click mybind.Position = mybind.Count - 1 End Sub
相关文章推荐
- VB.Net自己写的一个控件:ComboBox下拉列表中显示多列数据(可以绑定数据表)
- C#--第11周实验--任务3--设计一个窗体,窗体上有两个文本框,一个按钮,2个单选按钮--实现单击按钮后,根据单选按钮,将对应文本框中内容显示在标签。
- 【程序功能设计】先写一个在线留言本,实现用户的在线留言功能,留言信息存储到数据库,要求书籍数据表内容以及使用PHP编码完成。
- 有一个table表格,选中某一行后,点击“查看(button)”按钮可以实现对该行内容的显示
- 有一个table表格,选中某一行后,点击“查看(button)”按钮可以实现对该行内容的显示
- [VB.NET]同一个dataset可以绑定到不同datagridview里吗,并且每个datagridview显示内容不同
- ASP.NET使用ListView数据绑定控件和DataPager实现数据分页显示(一)
- ASP.NET使用ListView数据绑定控件和DataPager实现数据分页显示(二)
- [VB.NET]我打开网页的时候会弹出一个安全信息,然后出现:本页包含安全能容和不安全内容,是否显示不安全内容”请达人指教一下怎么删除这个提示
- Android采用ListView实现数据列表显示1-使用SimpleCursorAdapter进行数据绑定
- VB.NET中层次数据绑定TreeView的实现
- ADO 实例《创建一个临时数据库 创建一个临时数据表 GridView1绑定内容 以及Dataset_的使用》
- oracle12c JSON数据 使用SQL语句实现多表左外连接 显示无效数据 分页查询
- Asp.net使用jQuery实现数据绑定与分页
- vb.net 一个窗体在另一个窗体的容器内显示
- GridView那点事之【如何使用ExecuteReader()来绑定数据显示到表格中】 .
- 使用jquery点击一个实现button或连接,进行以下div显示,在点击隐藏
- 使用ES6的新特性Proxy来实现一个数据绑定实例
- VB.NET中层次数据绑定TreeView的实现
- 仅在ACCESS窗体设计中,实现数据文件连接的方法