SQL SERVER(46)图书管理系统之一数据库设计

  • 时间:
  • 浏览:
  • 来源:互联网

创建一个数据库bookmanager

添加两个数据表

图书信息表

用户表

打开VB,创建一个Windows应用程序

添加数据源

找到刚创建的数据库bookmanager,添加到项目里

创建一个PubFunction类

Imports System.Data.SqlClient
Public Class PubFunction
    Public Function GetConnection() As SqlConnection
        Return New SqlConnection(My.Settings.BookManagerConnectionString)
    End Function

    Public conn As SqlConnection

    Public Function nonQuery(ByVal strsql As String) As Integer
        conn = GetConnection()
        'MsgBox(conn.ConnectionString)
        Dim a As Integer = -1
        Try
            conn.Open()
            Dim comm As SqlCommand = New SqlCommand(strsql, conn)
            a = comm.ExecuteNonQuery
        Catch ex As Exception
        Finally
            conn.Close()
        End Try
        Return a
    End Function

    Public Function query(ByVal strsql As String) As DataSet
        conn = GetConnection()
        Dim ds As DataSet = New DataSet
        Try
            conn.Open()
            Dim adp As SqlDataAdapter = New SqlDataAdapter(strsql, conn)
            adp.Fill(ds)
        Catch ex As Exception
        Finally
            conn.Close()
        End Try
        Return ds
    End Function

    Public Sub Refresh()
        Dim pubf As New PubFunction
        Dim ds As New DataSet
        Dim strsql As String = "Select * from bookinfo"
        ds = pubf.query(strsql)
        Main.DataGridView1.DataSource = ds.Tables(0)
    End Sub
End Class

 

本文链接http://element-ui.cn/news/show-367379.aspx