Monday, May 31, 2010

Use stored procedure to insert data ( VB.NET ) WEB APPLICATION

Use stored procedure to insert data ( VB.NET ) WEB APPLICATION

Simple Guide line for Insert data with VB.NET web forms
( Code for save data calling SP)

-->Import namespace="system.data" Import namespace="system.data.sqlclient"


Private Sub Page_Load(ByVal Source As Object, ByVal E As EventArgs)

Dim sql As String = "InsertEmployee"
Dim strConnection As String = "Data Source=local;Initial Catalog=TestDB;User ID=sa;Password='111';"
Dim conn As New SqlConnection(strConnection)

conn.Open()

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

cmd.Parameters.Add("@FirstName", "ASMA")
cmd.Parameters.Add("@LastName", "QURESHI")

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