represent a db column value in a textbox

ssfftt

Well-known member
Joined
Oct 27, 2005
Messages
163
Programming Experience
1-3
[solved]represent a db column value in a textbox

I have these lines of code to retrieve a specific user from db, this user table contains USERNAME and PASSWORD. the sql selects both USERNAME and PASSWORD. I have a textbox called txtPW, when user click on "retrieve password" button, i want the password that corresponding to the input username appears in the textbox, Can any one help please?
VB.NET:
SqlDataAdapterPWReminder.SelectCommand.Parameters("@UNAME").Value = txtLoginName.Text
DataSetPWReminder.Clear()
SqlDataAdapterPWReminder.Fill(DataSetPWReminder)
 
Last edited:
Well if you have txtPW textbox show it in that box.
...and also you should set password charachter property of a txtPW to nothing (insted of * or whatever you use), or you can drag new textbox that will show password (I recomend that).

Search forum there are examples of that: search password login keywords.
 
For a single user/password query, dataset might be a little bit of overkill.

VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] sqlConn [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlClient.SqlConnection(strConn)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] sqlCmd [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] SqlClient.SqlCommand
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] sqlRead [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] SqlClient.SqlDataReader
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] strSQL [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]String
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Try[/COLOR][/SIZE][SIZE=2][SIZE=2]
  strSQL = "SELECT pwd FROM tblUsers WHERE usr = @User"
  sqlCmd = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlClient.SqlCommand(strSQL, sqlConn)
  sqlCmd.Parameters.Add("@User", txtPwd.text.Trim)
  sqlConn.Open()
  sqlRead = sqlCmd.ExecuteReader(CommandBehavior.SingleResult)
[/SIZE][SIZE=2][COLOR=#0000ff]  While[/COLOR][/SIZE][SIZE=2] sqlRead.Read
[/SIZE][SIZE=2][COLOR=#0000ff]    Me[/COLOR][/SIZE][SIZE=2].txtPwd.Text = sqlRead.GetSqlString(0)[/SIZE][/SIZE][SIZE=2]
[/SIZE][SIZE=2][COLOR=#0000ff]  End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]While
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Catch[/COLOR][/SIZE][SIZE=2] ex [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] SqlClient.SqlException
[/SIZE][SIZE=2][COLOR=#008000]  'Handle it
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Finally
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]  If[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Not[/COLOR][/SIZE][SIZE=2] sqlRead.IsClosed [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]    sqlRead.Close()
[/SIZE][SIZE=2][COLOR=#0000ff]  End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]  If[/COLOR][/SIZE][SIZE=2] sqlConn.State = ConnectionState.Open [/SIZE][SIZE=2][COLOR=#0000ff]Then
[/COLOR][/SIZE][SIZE=2]    sqlConn.Close()
[/SIZE][SIZE=2][COLOR=#0000ff]  End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]If
[/COLOR][/SIZE][SIZE=2]  sqlConn.Dispose()
  sqlCmd.Dispose()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Try
[/COLOR][/SIZE]

(I didn't test the code, it might take a couple small tweaks to make it work for you)
 
very helpful, sevenhalo, i modified it a bit so that i can use the components that i have, thx very much~
 
Back
Top