Click here to Skip to main content
15,907,687 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
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

SQL
Create Proc P_SelectAllRole  
As  
Select StatusId,Status from tblStatusMaster


What I have tried:

SQL
Create Proc P_SelectAllRole  
As  
Select StatusId,Status from tblStatusMaster
Posted
Updated 31-Aug-17 20:00pm
v2
Comments
PIEBALDconsult 1-Sep-17 0:04am    
And what happened?
Jayanta Modak 1-Sep-17 1:09am    
how can I do it.....
I want to don't open SQL Server Management Studio, But I want to add the stored procedure.

It is possible please help me
Jayanta Modak 1-Sep-17 1:43am    
actually i update some stored procedure and create 2 tables in my system. Now i want to update it on other system. i add a form name "Update_Database" and here a button same name when i click on this button create the stored procedure and create 2 tables automatically in the database. how i can do it please help me.......

1 solution

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:
VB
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
Creating a table is exactly the same procedure, but with CREATE TABLE commands instead of CREATE PROC.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900