欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

数据库开发012VB.NET操作SQL Server存储过程

程序员文章站 2022-05-07 14:33:12
...

SSMS新建一个无参数存储过程

use Sales
go
create proc sp_getGrade
as
select * from grade where 数学>60
go

数据库开发012VB.NET操作SQL Server存储过程

Imports System.Data.SqlClient
Public Class Form1
    Dim conn As SqlConnection
    Dim comm As SqlCommand
    
    Private Function GetConnection() As SqlConnection
        Return New SqlConnection(My.Settings.SalesConnectionString)
    End Function

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        
        Try
            conn = GetConnection()
            conn.Open()
            comm = New SqlCommand("sp_getGrade", conn)
            comm.CommandType = CommandType.StoredProcedure
            Dim ds As New DataSet
            Dim ad As New SqlDataAdapter(comm)
            ad.Fill(ds, "grade")
            conn.Close()

            DataGridView1.DataSource = ds.Tables("grade")
        Catch ex As Exception
            MsgBox("有错误")
        End Try

       
    End Sub
End Class

 

相关标签: 数据库开发