浅谈如何使用vb.net从数据库中提取数据
<p><span style="color: #ff0000"><strong>1.设置从Model中的Sub Main 启动</strong></span></p><p style="text-align: center"><img alt="" src="https://img.jbzj.com/file_images/article/202007/202007141706344.png?2020614171434" /></p>
<p><span style="color: #ff0000"><strong>2.程序结构</strong></span></p>
<p style="text-align: center"><img alt="" src="https://img.jbzj.com/file_images/article/202007/202007141706345.png?202061417157" /></p>
<p><span style="color: #ff0000"><strong>3.Model1</strong></span></p>
<div class="jb51code">
<pre class="brush:java;">
Imports System.Windows.Forms.Application
Module Module1
Sub Main()
'form1 是测试多文档窗口
'Dim frm1 As New Form1()
'frm1.Show()
Dim formStudentSysMain As New FormStudentSysMain()
formStudentSysMain.Show()
Do While True
DoEvents()
Loop
End Sub
End Module</pre>
</div>
<p><span style="color: #ff0000"><strong>4.FormStudentSysMain.vb</strong></span></p>
<p style="text-align: center"><img alt="" src="https://img.jbzj.com/file_images/article/202007/202007141706356.png?2020614171536" /></p>
<div class="jb51code">
<pre class="brush:java;">
Imports System.Data.SqlClient
Public Class FormStudentSysMain
Public DBConnstr As String = "Data Source=LJJ-FF\LJJ;Initial Catalog=TestMvc;User ID=sa;Password=111111"
Private Sub quitMenuItem_Click(sender As Object, e As EventArgs) Handles quitMenuItem.Click
End
End Sub
Private Sub selectinfoMenuItem_Click(sender As Object, e As EventArgs) Handles selectinfoMenuItem.Click
Dim formSearchStudent As New FormSearchStudent
formSearchStudent.MdiParent = Me
formSearchStudent.WindowState = FormWindowState.Normal
formSearchStudent.Show()
End Sub
Private Sub updateinfoMenuItem1_Click(sender As Object, e As EventArgs) Handles updateinfoMenuItem1.Click
Dim formStudentInfo As New FormStudentInfo
FormSearchStudent.MdiParent = Me
FormSearchStudent.WindowState = FormWindowState.Normal
formStudentInfo.Show()
End Sub
Private Sub importscoreMenuItem_Click(sender As Object, e As EventArgs) Handles importscoreMenuItem.Click
Dim formStudentCourse As New FormStudentCourse
FormSearchStudent.MdiParent = Me
FormSearchStudent.WindowState = FormWindowState.Normal
formStudentCourse.Show()
End Sub
Private Sub cascadeMenuItem_Click(sender As Object, e As EventArgs) Handles cascadeMenuItem.Click
Me.LayoutMdi(MdiLayout.Cascade)
End Sub
Private Sub horizonMenuItem_Click(sender As Object, e As EventArgs) Handles horizonMenuItem.Click
Me.LayoutMdi(MdiLayout.TileHorizontal)
End Sub
Private Sub verticalMenuItem_Click(sender As Object, e As EventArgs) Handles verticalMenuItem.Click
Me.LayoutMdi(MdiLayout.TileVertical)
End Sub
Private Sub FormStudentSysMain_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class</pre>
</div>
<p><span style="color: #ff0000"><strong>5.FormSearchStudent.vb</strong></span></p>
<p style="text-align: center"><img alt="" src="https://img.jbzj.com/file_images/article/202007/202007141706357.png?202061417168" /></p>
<div class="jb51code">
<pre class="brush:java;">
Imports System.Data.SqlClient
Public Class FormSearchStudent
Private Sub Label1_Click(sender As Object, e As EventArgs) Handles Label1.Click
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim sqlConStr As String = My.Forms.FormStudentSysMain.DBConnstr
Dim sqlStr As String = "select * from student "
Dim sqlDataAdapter As New SqlDataAdapter
Dim dataSet As New DataSet
Dim sqlConnection As New SqlConnection(sqlConStr)
If Trim(txtName.Text) <> "" Then
sqlStr = sqlStr & "where name like '%" & Trim(txtName.Text) & "%'"
End If
sqlDataAdapter.SelectCommand = New SqlCommand(sqlStr, sqlConnection)
sqlConnection.Open()
sqlDataAdapter.Fill(dataSet)
sqlConnection.Close()
DataGridView1.DataSource = dataSet.Tables(0)
End Sub
Private Sub FormSearchStudent_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
End Class</pre>
</div>
<p><span style="color: #ff0000"><strong>6.运行结果</strong></span></p>
<p style="text-align: left">到此这篇关于浅谈如何使用vb.net从数据库中提取数据的文章就介绍到这了,更多相关vb.net从数据库中提取数据内容请搜索琼殿技术社区以前的文章或继续浏览下面的相关文章希望大家以后多多支持琼殿技术社区!</p>
<div class="art_xg">
<b>您可能感兴趣的文章:</b><ul><li>Asp.Net Core中创建多DbContext并迁移到数据库的步骤</li><li>在.NetCore(C#)中使用ODP.NET Core+Dapper操作Oracle数据库</li><li>asp.net实现存储和读取数据库图片</li><li>.NET Core Dapper操作mysql数据库的实现方法</li><li>C# Ado.net实现读取SQLServer数据库存储过程列表及参数信息示例</li><li>ASP.NET Core2读写InfluxDB时序数据库的方法教程</li><li>ASP.NET WebAPI连接数据库的方法</li><li>.net core利用orm如何操作mysql数据库详解</li><li>.net core下配置访问数据库操作</li><li>.net数据库操作框架SqlSugar的简单入门</li></ul>
</div>
</div>
<!--endmain-->
頁:
[1]