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

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.......

i hope it will help
I have a access connection with textbox as data feeder to database change it to SQL if u want.
The code is:
 Imports System
Imports System.Data
Imports System.Data.OleDb
Public Class Form2
  Dim conaccess As New OleDbConnection
  Dim conreader As OleDbDataReader
  Dim concmd As New OleDbCommand
  Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  DataGridView1.EditMode = False
  conaccess.ConnectionString = "Provider=Microsoft.jet.oledb.4.0;data source=d:\vijay.mdb"
   conaccess.Open()
   loadGrid()
   End Sub
   Private Sub loadGrid()
   Dim access As String
  access = "select * from vijay"
  Dim DataTab As New DataTable
 Dim DataAdap As New OleDbDataAdapter(access, conaccess)
 DataAdap.Fill(DataTab)
DataGridView1.DataSource = DataTab
End Sub
Private Sub new_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles new_btn.Click
  Dim no As String
   no = "select Max(ID) from vijay"
   Dim concmd As New OleDbCommand(no, conaccess)
   conreader = concmd.ExecuteReader
        If (conreader.Read) Then
            If (IsDBNull(conreader(0))) Then
                id_txt.Text = "1"
            Else
                id_txt.Text = conreader(0) + 1
            End If
            name_txt.Clear()
            branch_txt.Clear()
            age_txt.Clear()
            class_txt.Clear()
            gen_txt.Clear()
        End If
    End Sub
     Private Sub DataGridView1_CellClick(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DataGridView1.CellClick
        Dim i As Integer
         i = DataGridView1.CurrentRow.Index
        Try
            id_txt.Text = DataGridView1.Item(0, i).Value
            name_txt.Text = DataGridView1.Item(1, i).Value
            class_txt.Text = DataGridView1.Item(2, i).Value
            gen_txt.Text = DataGridView1.Item(3, i).Value
            branch_txt.Text = DataGridView1.Item(4, i).Value
            age_txt.Text = DataGridView1.Item(5, i).Value
        Catch ex As Exception
         End Try
            End Sub
    Private Sub del_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles del_btn.Click
        Dim delcmd As New OleDbCommand("delete from vijay where id=" & id_txt.Text & " ", conaccess)
        delcmd.ExecuteNonQuery()
        MsgBox("Record is deleted")
        loadGrid()
        id_txt.Clear()
        name_txt.Clear()
        branch_txt.Clear()
        age_txt.Clear()
        class_txt.Clear()
        gen_txt.Clear()
    End Sub
     Private Sub save_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save_btn.Click
        Dim access As String = String.Format("INSERT INTO vijay (Name,Class,Branch,Gender,Age) VALUES('{0}','{1}','{2}','{3}','{4}')", name_txt.Text, class_txt.Text, branch_txt.Text, gen_txt.Text, age_txt.Text)
        concmd.Connection = conaccess
        concmd.CommandText = access
        concmd.ExecuteNonQuery()
        MsgBox("Record Successfully Saved")
        loadGrid()
        id_txt.Clear()
        name_txt.Clear()
        branch_txt.Clear()
        age_txt.Clear()
        class_txt.Clear()
        gen_txt.Clear()
    End Sub
     Private Sub up_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles up_btn.Click
        Dim access As String
        access = "UPDATE vijay SET Name = '" & name_txt.Text & "', Age = '" & age_txt.Text & "', Gender ='" & gen_txt.Text & "' , Branch ='" & branch_txt.Text & "' , Class = '" & class_txt.Text & "' where id=" & id_txt.Text & ""
        Dim cmd As New OleDbCommand(access, conaccess)
        cmd.ExecuteNonQuery()
        loadGrid()
        id_txt.Clear()
        name_txt.Clear()
        branch_txt.Clear()
        age_txt.Clear()
        class_txt.Clear()
        gen_txt.Clear()
     End Sub
End Class
Source:https://www.codeproject.com/
Mahe,

Fusion financials training

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.