需要帮助来更改密码表格 [英] need help to change password form
问题描述
大家好,我仍然是vb.net 2008的新手.
我正在尝试更改密码形式
我要做的是,当我单击更改密码"按钮时,用户必须输入旧密码,新密码并确认新密码
我正在使用sql server 2005,我的朋友告诉我使用sqlcommandbuilder
任何人都可以帮助我??
hi everyone, i am still newbie in vb.net 2008
i am try to make change pasword form
what i want to do is when i click change pasword button then user must input old paswword , new pasword and confirm the new pasword
i am using sql server 2005 and my friend told me to use sqlcommandbuilder
anyone can help me ??
Imports System.Data.SqlClient
Public Class frm_chPass
Dim conn As SqlConnection
Dim da As SqlDataAdapter, dt As New DataTable, dtv As New DataView
Private Sub btn_exit Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Me.Close()
End Sub
Private Sub kunciobjek()
txt_confirm.ReadOnly = True
txt_new.ReadOnly = True
txt_old.ReadOnly = True
End Sub
Private Sub bukaobjek()
txt_confirm.ReadOnly = False
txt_new.ReadOnly = False
txt_old.ReadOnly = False
End Sub
Private Sub frm_chPass_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim cons As String = ("data source=TONNY\SQLEXPRESS;initial catalog=APP;Persist security info=true;uid=sa;password=sally")
conn = New SqlConnection(cons)
conn.Open()
da = New SqlDataAdapter("select * from tbl_user", cons)
Dim cb As New SqlCommandBuilder(da)
da.Fill(dt)
kunciobjek()
End Sub
Private Sub Btn_save_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.BindingContext(dt).EndCurrentEdit()
da.Update(dt)
End Sub
Private Sub Btn_changepasword(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
bukaobjek()
End Sub
End Class
任何人都可以帮助我,我仍然是个新手,所以需要您的帮助..idunno在button1中做什么(按钮更改密码)
anyone can hel me plz T__T i am still so newbie so need your help..i dunno what to do in button1(button to change pasword)
推荐答案
您好朋友. .
您可以通过两种方式来完成此操作.
1)使用在VB.NET中完成的所有代码
2)使用存储过程
1)使用在VB.NET中完成的所有代码
注意:
下面的所有代码都是用vb.net在asp.net中完成的,您需要根据需要进行更改"
Hello friend..
You Can do this by Two Way..
1) Using all code done in VB.NET
2) Using a Store Procedure
1)Using all code done in VB.NET
NOTE:
"all the code below is done in asp.net with vb.net you need to change as per your requirment"
Imports System.Data.SqlClient
Imports System.Data
Public Class _Default
Inherits System.Web.UI.Page
Dim sqlCon As SqlConnection
Dim sqlDa As SqlDataAdapter
Dim dt As DataTable
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If (Not IsPostBack) Then
sqlCon = New SqlConnection("Your Connection string goes here")
End If
End Sub
Protected Sub btnChangePass_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnChangePass.Click
Dim userName As String
Dim oldPass As String = txtOldPass.Text
Dim newPass As String = txtNewPass.Text
If (oldPass.Equals(newPass)) Then
userName = "Your User Name Goes Here"
dt = New DataTable()
sqlCon.Open()
sqlDa.SelectCommand = New SqlCommand("SELECT * FROM USERTABLE WHERE USERNAME = @UserName AND PASS = @Pass", sqlCon)
sqlDa.SelectCommand.Parameters.AddWithValue("@UserName", userName)
sqlDa.SelectCommand.Parameters.AddWithValue("@UserName", oldPass)
dt.Clear()
sqlDa.Fill(dt)
If (dt.Rows.Count > 0) Then
Dim userID As String = dt.Rows(0)("YOUR ID COLUMN").ToString()
sqlDa.UpdateCommand = New SqlCommand("UPDATE USERTABLE SET PASS = @NewPass WHERE UserID = @UserID", sqlCon)
sqlDa.UpdateCommand.Parameters.AddWithValue("@NewPass", newPass)
sqlDa.UpdateCommand.Parameters.AddWithValue("@UserID", userID)
sqlDa.UpdateCommand.ExecuteNonQuery()
End If
Else
'display your password not match message to user
End If
End Sub
End Class
2)使用存储过程
2) Using a Store Procedure
CREATE PROCEDURE SP_CHANGE_PASS
-- Add the parameters for the stored procedure here
@UserName nvarchar(20),
@OldPass nvarchar(20),
@newPass nvarchar(20),
@ResultID int = NULL
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
SELECT @ResultID = ID FROM TestTable WHERE Name = @UserName AND pass = @OldPass
IF(@ResultID IS NOT NULL)
BEGIN
UPDATE TestTable SET pass = @newPass WHERE ID = @ResultID
END
END
GO
要使用此sp,您需要传递三个参数,例如用户名,oldPass和new pass,
只需调用该sp,它将为您完成所有更改密码的工作.
您还可以添加此sp的结果的输出参数,以便在vb.net的代码页中使用
For use of this sp you need to pass three parameter like user name, oldPass and new pass,
just only call that sp and it will done all your work for you of changing password.
you can also add a output parameter as result of this sp for you use in code page of vb.net
这篇关于需要帮助来更改密码表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!