有一个格兰仕,我必须从数据库中向文本框写入一个值 [英] have a glanse, i have to write a value to textbox from database
本文介绍了有一个格兰仕,我必须从数据库中向文本框写入一个值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
(VB.net)
我使用DAL和BLL,在这里我要检查用户是否存在(Textbox1),如果存在,则将用户密码从Db写入Textbox2,并且textbox2文本模式应为password.
这是我的代码:
(VB.net )
im using DAL and BLL, here i want to check whether user exists(Textbox1) or not, if user exists then write the users password from Db to Textbox2 and textbox2 text mode should be password.
here is my code:
Protected Sub button1_click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim productslogic As New productsBLL()
GridView1.DataSource = productslogic.GetDataByname(TextBox1.Text)
GridView1.DataBind()
Dim mydataset As New DataSet
Dim strconnection As SqlConnection
strconnection = New SqlConnection(ConfigurationManager.ConnectionStrings("masterConnectionString").ConnectionString)
strconnection.Open()
Dim myData As New SqlDataAdapter("select * from asaa where name='" & TextBox1.Text & "' ", strconnection)
Dim dr As SqlDataReader
myData.TableMappings.Add("Table", "ak")
myData.Fill(mydataset)
GridView1.DataSource = mydataset.Tables(0).DefaultView
GridView1.DataBind()
TextBox2.TextMode = TextBoxMode.Password
TextBox2.Text = mydataset.Tables(0).Rows(1)(1).ToString()
如果用户存在,请告诉我如何检索密码到textbox2.
我不想直接使用连接数据集或数据适配器应使用BLL
please tell me how to retrieve the password to textbox2 if user exists.
i dont want to use connection directly dataset or dataadapter should use BLL
please help with some code
推荐答案
hello,
为什么要使查询如此复杂,亲爱的只有2个文本框,您就完成了
她的代码,但我仍然不明白为什么您希望密码出现在textbox2上,因为它反而可能会损害应用程序的安全性.她的代码也是您想要将textbox2模式设置为password的,所以有什么用
说明:我没有使用过datagrid,因为没有datagrid即可完成此操作,请加密您的密码,然后将其保存到数据库中
hello,
why to make the query so complex dear just have 2 textbox and you are done
hers your code but i still don''t get it why you want the password to appear on textbox2 as it may harm the applications security anyways her''s your code also you wana set the textbox2 mode to password so whats the use
Explanation: I have not used datagrid as this can be done without datagrid and please encrypt your password and then save them to database
Imports System.Data.SqlClient
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As SqlConnection = New SqlConnection("Data Source=.;Initial Catalog=master;Integrated Security=True")
con.Open()
Dim query As String = "select pass from mytable where user1=''" + TextBox1.Text + "''"
Dim cmd As SqlCommand = New SqlCommand(query, con)
Dim da As SqlDataReader = cmd.ExecuteReader()
If (da.Read() = True) Then
TextBox2.Text = da(0).ToString()
TextBox2.UseSystemPasswordChar = True
Else
MessageBox.Show("Database scan complete no such user found")
End If
con.Close()
con.Dispose()
End Sub
End Class
一旦找到有用的答案,就对我的答案进行评分
谢谢&问候
基数:)
Do rate my answer once you find it useful
Thanks & Regards
Radix :)
您无法设置密码文本框的文本.
You can''t set the text for a password textbox.
这篇关于有一个格兰仕,我必须从数据库中向文本框写入一个值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文