单击按钮时如何从数据库中获取特定值 [英] How Do I Get A Specific Value From A Database When I Click A Button

查看:88
本文介绍了单击按钮时如何从数据库中获取特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好



我需要设计登录。当用户输入用户名时,输入的文本必须自动搜索数据库,然后当他输入密码并单击提交时,如果密码与用户名匹配,则应将其重定向到User.aspx。

这里是文本框和按钮:

< asp:TextBox CssClass =inputID =Usernamerunat =serverplaceholder =lynda>



< asp:TextBox CssClass =inputID =密码runat =server占位符=密码TextMode =密码>



< asp:Button ID =Button1CssClass =buttonrunat =serverText =SubmitOnClick =Button1_Click/>



这里是数据库:

Hello

i need to design a login. When the user enters his username, the text that has been inputted must automatically search through the database then when he enters his password and clicks submit, he should be redirected to User.aspx if the password matches the username.
here are the textboxes and button:
<asp:TextBox CssClass="input" ID="Username" runat="server" placeholder="lynda" >

<asp:TextBox CssClass="input" ID="Password" runat="server" placeholder="Password" TextMode="Password">

<asp:Button ID="Button1" CssClass="button" runat="server" Text="Submit" OnClick="Button1_Click" />

here is the database:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="SqlDataSource1">
            <Columns>
                <asp:BoundField DataField="ID" HeaderText="ID" InsertVisible="False" ReadOnly="True" SortExpression="ID" />
                <asp:BoundField DataField="Username" HeaderText="Username" SortExpression="Username" />
                <asp:BoundField DataField="Password" HeaderText="Password" SortExpression="Password" />
                <asp:BoundField DataField="LoginRetrieveQuestion" HeaderText="LoginRetrieveQuestion" SortExpression="LoginRetrieveQuestion" />
                <asp:BoundField DataField="LoginRetrieveAnswer" HeaderText="LoginRetrieveAnswer" SortExpression="LoginRetrieveAnswer" />
                <asp:BoundField DataField="Client" HeaderText="Client" SortExpression="Client" />
            </Columns>
        </asp:GridView>
        <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:ConnectionString %>" ProviderName="<%$ ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT [ID], [Username], [Password], [LoginRetrieveQuestion], [LoginRetrieveAnswer], [Client] FROM [LoginTable]"></asp:SqlDataSource>





我尝试了很多方法,但我无法做到。需要你的帮助



ive tried alot of ways but i just couldnt do it. Your help is needed

推荐答案

ConnectionStrings:ConnectionString %> ProviderName = <%
ConnectionStrings:ConnectionString %>" ProviderName="<%


ConnectionStrings:ConnectionString.ProviderName %> SelectCommand = SELECT [ID],[Username],[Password],[LoginRetrieveQuestion],[LoginRetrieveAnswer],[Client] FROM [LoginTable] > < / asp:SqlDataSource >
ConnectionStrings:ConnectionString.ProviderName %>" SelectCommand="SELECT [ID], [Username], [Password], [LoginRetrieveQuestion], [LoginRetrieveAnswer], [Client] FROM [LoginTable]"></asp:SqlDataSource>





我尝试了很多方法,但我无法做到t。需要你的帮助



ive tried alot of ways but i just couldnt do it. Your help is needed


请停止重新发明轮子。

这样做有一个更简单,更有效,更安全的方法: MSDN:会员简介 [ ^ ]
Please, stop reinventing the wheel.
There is a much simpler, much more effective, and much more secure way of doing this: MSDN: Introduction to Membership[^]


这篇关于单击按钮时如何从数据库中获取特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆