Imports System.Data
Imports System.Data.SqlClient
Partial Class web_repass
Inherits System.Web.UI.Page
Dim Cons As String = Class1.Constr3
Dim DA As SqlDataAdapter
Dim DS As DataSet
Dim DT As DataTable
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
Dim Sql As String = "Select username From customer"
DA = New SqlDataAdapter(Sql, Cons)
DS = New DataSet
DA.Fill(DS, "user")
DT = DS.Tables("user")
Session("Data") = DT
Else
DT = Session("Data")
End If
Msg.Text = ""
Msg.BackColor = Drawing.Color.LightYellow
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim newPassword As String
If usernametxt.Text = "" Then
Msg.Text = "กรุณากรอก username"
ElseIf usernametxt.Text <> Session("data").ToString Then
Msg.Text = "username " & Server.HtmlEncode(usernametxt.Text) & " not found. Please check the value and re-enter."
Else
Msg.Text = "Password reset. Your new password is: " & Server.HtmlEncode(newPassword)
End If
End Sub
End Class
ปล. ตรง eles ผมไม่ทราบจริงว่าจะทำยังไง เป็นมือใหม่ครับ รับคำชีแนะทุกอย่างครับ
Tag : .NET, Ms SQL Server 2008, Web (ASP.NET), VB.NET, VS 2010 (.NET 4.x)
Dim objConn As New System.Data.SqlClient.SqlConnection
Dim dtAdapter As System.Data.SqlClient.SqlDataAdapter
Dim dt As New DataTable
Dim strConnString As String
strConnString = "Server=localhost;UID=sa;PASSWORD=;database=mydatabase;Max Pool Size=400;Connect Timeout=600;"
objConn = New System.Data.SqlClient.SqlConnection(strConnString)
objConn.Open()
Dim strSQL As String
strSQL = "SELECT * FROM customer WHERE Username = '" & Me.txtUser.Text & "' "
dtAdapter = New System.Data.SqlClient.SqlDataAdapter(strSQL, objConn)
dtAdapter.Fill(dt)
dtAdapter = Nothing
objConn.Close()
objConn = Nothing
IF dt.Rows.Count = 0 Then
Me.lblStatus.Text = "Not Found Username"
Else
Me.lblStatus.Text = "Password = " & dt.Rows(0)("Password").ToString()
End IF