如何从vb.net更新SQL数据库... [英] How to update SQL database from vb.net...

查看:120
本文介绍了如何从vb.net更新SQL数据库...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何从vb.net 2010更新Sql数据库我想在点击按钮时从登录时间在sql数据库中添加一个存储过程..



数据库名称

db17-18



存储过程



How to Update Sql database from vb.net 2010 i want to add a stored procedure in sql database from login time on button click..

database name
db17-18

stored procedure

Create Proc P_SelectAllRole  
As  
Select StatusId,Status from tblStatusMaster




我的尝试:





What I have tried:

Create Proc P_SelectAllRole  
As  
Select StatusId,Status from tblStatusMaster

推荐答案

从VB创建存储过程的过程完全相同从SSMS开始 - 它只是一系列创建它的SQL命令。



所以你做通常的事情:创建一个SqlConnection对象,打开它。在该连接上创建一个SqlCommand对象,并为其创建SP create命令作为命令字符串:

Creating a stored procedure from VB is exactly the same process as from SSMS - it is just a series of SQL commands which creates it.

So you do the usual things: create a SqlConnection object, open it. Create a SqlCommand object on that connection, and give it the SP create commands as the command string:
Using con As New SqlConnection(strConnect)
    con.Open()
        Dim strCreateSP As String = "CREATE PROC [dbo].Sample
                                        @ID INT
                                     AS
                                     BEGIN
                                        SELECT * FROM myTable WHERE iD=@ID;
                                     END"
    Using com As New SqlCommand(strCreateSP, con)
        com.ExecuteNonQuery()
    End Using
End Using

创建表是完全相同的过程,但使用CREATE TABLE命令而不是CREATE PROC。

Creating a table is exactly the same procedure, but with CREATE TABLE commands instead of CREATE PROC.


这篇关于如何从vb.net更新SQL数据库...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆