前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >vb.net从数据库中取数据

vb.net从数据库中取数据

作者头像
全栈程序员站长
发布2022-09-06 20:11:41
2.1K0
发布2022-09-06 20:11:41
举报
文章被收录于专栏:全栈程序员必看

大家好,又见面了,我是你们的朋友全栈君。

1.设置从Model中的Sub Main 启动

2.程序结构

3.Model1

代码语言:javascript
复制
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

4.FormStudentSysMain.vb

代码语言:javascript
复制
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

5.FormSearchStudent.vb

代码语言:javascript
复制
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

6.运行结果

发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/155767.html原文链接:https://javaforall.cn

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档