社区
ASP
帖子详情
asp 登陆界面连接sql数据库完成登录怎么做?求大神帮忙
qq_25744253
2015-01-31 10:30:11
vs2012建了个asp登录界面,想连接数据库完成这个过程,sql 2008 建了表了,username和password,小白一个弄了半天没弄好,求大神帮帮忙
...全文
477
4
打赏
收藏
asp 登陆界面连接sql数据库完成登录怎么做?求大神帮忙
vs2012建了个asp登录界面,想连接数据库完成这个过程,sql 2008 建了表了,username和password,小白一个弄了半天没弄好,求大神帮帮忙
复制链接
扫一扫
分享
转发到动态
举报
写回复
配置赞助广告
用AI写文章
4 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
qq_25744253
2015-02-02
打赏
举报
回复
大神都忙,还好自己搞定了,就这样结贴吧
qq_25744253
2015-02-02
打赏
举报
回复
protected void button1_Click(object sender, EventArgs e) { string str = WebConfigurationManager.ConnectionStrings["con"].ToString(); string user = uname.Text; string pwd = upwd.Text; SqlConnection conn = new SqlConnection(str); string sqlsel = "select * from logininfor where username="+user+" and password="+pwd; SqlCommand comm = new SqlCommand(sqlsel,conn ); //"Select * from logininfor where username="+user+"and password="+pwd" SqlDataReader dr; //comm.Connection = conn; conn.Open(); dr = comm.ExecuteReader(); if (dr.HasRows) { Server.Execute("main.html"); Response.Write("<script>alert('登录成功');</script>"); conn.Close(); } else { Response.Write("登录失败"); conn.Close(); } } 改写了一下代码,还是不行,提示说列名无效
qq_25744253
2015-02-01
打赏
举报
回复
<configuration> <connectionStrings> <add name="con" connectionString="Data Source=localhost;Database=testproject;uid=用户名;pwd=密码" /> </connectionStrings> <system.web> <compilation debug="true" targetFramework="4.5" /> <httpRuntime targetFramework="4.5" /> </system.web> </configuration> 以上是Web.config的内容。 <form id="form1" runat="server"> <div> 用户名:<asp:TextBox ID="uname" runat="server" ></asp:TextBox><br /> 密 码: <asp:TextBox ID="upwd" runat="server" TextMode="Password" ></asp:TextBox><br /> <asp:Button ID="button1" runat="server" Text="提交" onclientclick="button1_Click()"/> </div> </form> 以上是我登陆界面的主要代码; using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Web.Configuration; namespace test1 { public partial class login : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { string str = WebConfigurationManager.ConnectionStrings["con"].ToString(); SqlCommand comm = new SqlCommand("Select * from logininfor"); string user = uname.Text.ToString(); string pwd = upwd.Text.ToString(); SqlDataReader dr; SqlConnection conn = new SqlConnection(str); conn.Open(); comm.Connection = conn; dr = comm.ExecuteReader(); if (dr.HasRows) { //Server.Execute("main.html"); Response.Write("<script>alert('登录成功');</script>"); } else { Response.Write("登录失败"); } } 这是login.aspx.cs的代码,现在只要我一打开页面不输入用户名和密码就直接弹出登录成功的对话框了,登录按钮的事件怎么写?我知道写在页面加载事件里是不对的,但不知道怎么把写的单击事件和按钮关联起来,还有什么都没输入就弹出登录成功对话框是为什么?求各位大侠帮忙解释一下
孟子E章
2015-02-01
打赏
举报
回复
数据库连接的写法可能存在问题,根本连不上数据库 另外,asp连接需要安装 Microsoft® SQL Server® 2008 R2 功能包 中的 Microsoft® SQL Server® 2008 R2 Native Client 下载地址 展开安装说明找 Microsoft® SQL Server® 2008 R2 Native Client http://www.microsoft.com/zh-cn/download/details.aspx?id=16978
asp
.net
连接
SQL
数据库
做
登录
由于项目的需要,找的一些列子。以备查看。 using System;using System.Collections;using System.ComponentModel;using System.Data;using System.Drawing;using System.Web;using System.Web.SessionState;using Sys
ASP
连接
SQL
2000
数据库
,用户'/
ASP
NET'无法登陆的解决方案
在web.config配置文件中,(安装时选择windows的验证模式),
连接
数据库
,出现用户/
ASP
NET无法登陆。原因是在
SQl
中,用户名没有此权限,在
数据库
的“安全性”选项中,选择登陆,选择“/
ASP
NET”,右键,属性,设置用户的权限为DB-owner,即可解决。
asp
.net my
sql
登陆_
ASP
.NET +
Sql
Server (vs2015)登陆功能实现
First step:1 用户数据准备在
sql
server中准备所需要的数据:所需要的
数据库
【test_login】以及表【user_inf】表【user_inf】中的数据:表中的数据Second step:2 新建一个
asp
.net工程新建项目选择项目类型选择模板,此处可根据不同情况有不同选则此处直接跳过即可然后新建一个项目就
完成
了,因为之前选择的Empty,现在项目中什么都没有。Third ...
在
asp
.net中创建一个简单的
登录
界面,用与
sql
2008
数据库
相连
本人小白,望各位
大神
在空暇时候动动手指,过程能尽量详细最好,再次感激不尽!!!
ASP
28,404
社区成员
356,942
社区内容
发帖
与我相关
我的任务
ASP
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
复制链接
扫一扫
分享
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章