vb.net从数据库中取数据

vb.net从数据库中取数据1.设置从Model中的SubMain启动2.程序结构3.Model14.FormStudentSysMain.vb5.FormSearchStudent.vb6.运行结果

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

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

<span role="heading" aria-level="2">vb.net从数据库中取数据

2.程序结构

<span role="heading" aria-level="2">vb.net从数据库中取数据

3.Model1

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

<span role="heading" aria-level="2">vb.net从数据库中取数据

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

<span role="heading" aria-level="2">vb.net从数据库中取数据

 

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.运行结果

<span role="heading" aria-level="2">vb.net从数据库中取数据

 

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

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

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • STM32F103驱动GT911

    STM32F103驱动GT9110x00引脚连接://SCL——-PB10//SDA——-PB11//INT——–PB1//RST——–PB2IIC的SCL与SDA需要接上拉电阻!0x01模拟IIC:在模拟IIC的头文件中:定义所需的IO操作宏://IO操作函数#defineIIC_SCLPBout(10)//…

    2022年6月30日
    32
  • busybox配置telnetd

    busybox配置telnetd

    2021年11月15日
    84
  • java函数式编程:四大Function

    java函数式编程:四大Functionjava util function 包下的四大 Function1 Consumer 消费者 publicinterf T voidaccept Tt 从名字可以看出 消费者是来消费的 它接受一个数据 没有任何返回值 简单使用 比如我们只想打印列表中的每个元素 这里的 forEach Consumer 里面接受的参数就是一个 C T

    2025年9月3日
    0
  • 阿帕基_jojo唯一一个没有荒木线的人

    阿帕基_jojo唯一一个没有荒木线的人阿帕基死前脑海里浮现的场景阿帕基:你在那里干什么啊?警察先生警察:抱歉打扰你吃饭了,我正在调查,我在采集指纹,昨晚,对面人行道上发生了一起抢劫案,被害者被人用酒瓶殴打,碎片散了一地。但人行道上的碎

    2022年8月1日
    5
  • vue filters过滤器的统一封装「建议收藏」

    vue filters过滤器的统一封装「建议收藏」目录统一封装规则统一封装规则1、src文件夹下创建filters文件夹,然后再filters文件夹下创建index.js即:src/filters/index.js2、在main.js中引入src/filters/index.js文件,并在下方遍历调用filters中的方法,使用VUE.filters切记:将遍历代码写在newVUE()上方3、在src/utils文件夹下的文件中创建各种工具类方法4、在src/filters/index.js中引入utils中的方法进行调用src

    2022年5月22日
    37
  • 地形分析的主要内容(流浪地球的特效水平)

    早期的天龙八部跟武侠世界基本相似。先简单地说一下载入场景的大致过程:     读取.Scene文件     根据读取.Terrain文件     读取地砖大小()地形大小(,),缩放值()。     读取所有要用的地形贴图(中各项)。     读取.g

    2022年4月15日
    49

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号