Use stored procedure to insert data : Stored Procedure SqlConnection « ADO.net Database « ASP.Net






Use stored procedure to insert data

<%@ Import namespace="system.data" %>
<%@ Import namespace="system.data.sqlclient" %>

<script language="vb" runat="server">
Private Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs)

  Dim sql As String = "InsertEmployee"
  Dim strConnection As String = "Data Source=whsql-v08.prod.mesa1.secureserver.net;Initial Catalog=DB_49907;User ID=java2suser;Password='password';"
  Dim conn As New SqlConnection(strConnection)

  conn.Open()

  Dim cmd As New SqlCommand(sql, conn)
  cmd.CommandType = CommandType.StoredProcedure

  cmd.Parameters.Add("@FirstName", "M")
  cmd.Parameters.Add("@LastName", "S")

  Try
    cmd.ExecuteNonQuery()
  Catch ex As Exception
    Response.Write("Error: " & ex.Message & "<br/>")
  End Try
    cmd.Connection.Close()
  End Sub
</script>

           
       








Related examples in the same category

1.Retrieving Data from a Stored Procedure
2.Call store procedure
3.Call store procedure through SqlConnection
4.Using Stored Procedures