SAVE DATA ON SQL SERVER THROUGH CALLING SP ( VB.NET FORMS )
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim sqlSP As String = "stp_InsertUser"
Dim strConnection As String = "Data Source=.;Initial Catalog=DATAbaseName;User ID=sa;Password='111';"
Dim conn As New SqlConnection(strConnection)
conn.Open()
Dim cmd As New SqlCommand(sqlSP, conn)
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.Add(New SqlParameter("@UserLogin", SqlDbType.VarChar, 100, ParameterDirection.Input, _
False, 0, 0, "", DataRowVersion.Proposed, UsernameTextBox.Text))
cmd.Parameters.Add(New SqlParameter("@UserPwd", SqlDbType.VarChar, 100, ParameterDirection.Input, _
False, 0, 0, "", DataRowVersion.Proposed, PasswordTextBox.Text))
Try
cmd.ExecuteNonQuery()
MsgBox("User Added successfully ", MsgBoxStyle.OkOnly)
Catch ex As Exception
MsgBox("Please Enter UserName.", MsgBoxStyle.Critical)
End Try
cmd.Connection.Close()
End Sub
-------------------------------------------------------------------------------------
SQL SERVER Stored procedure ) SP
Create PROCEDURE [dbo].[stp_InsertUser]
@UserLogin nvarchar(100),
@UserPwd nvarchar(100)
AS
--SET NOCOUNT ON
INSERT [dbo].[tblUser]
(
[UserLogin],
[UserPwd]
)
VALUES
(
@UserLogin,
@UserPwd
)
nice post thanks
ReplyDelete