码迷,mamicode.com
首页 > 数据库 > 详细

vb.net从数据库中取数据

时间:2019-08-31 21:12:24      阅读:169      评论:0      收藏:0      [点我收藏+]

标签:结构   do while   rms   height   mybase   sel   多文档   cat   ada   

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

技术图片

2.程序结构

技术图片

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

技术图片

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

技术图片

 

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

技术图片

 

vb.net从数据库中取数据

标签:结构   do while   rms   height   mybase   sel   多文档   cat   ada   

原文地址:https://www.cnblogs.com/sxjljj/p/11440308.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!