CSharp SQLServer 登陆
=======后台SQLServer存储过程================
--创建数据库
create database Stu;
--创建表
use MyShool;
if exists(select * from sys.tables where name='student')
drop table student;
go
create table Student(
stuId int identity(1,1) primary key,
stuName varchar(50) null,
stuPwd varchar(50) null,
stuAge int null,
);
--插入数值
Insert into student(stuName,stuPwd,stuAge) values('张三',123,10);
Insert into student(stuName,stuPwd,stuAge) values('王五',123,20);
Insert into student(stuName,stuPwd,stuAge) values('李四',123,30);
Insert into student(stuName,stuPwd,stuAge) values('赵六',123,40);
commit;
--查询数据
select * from student;
--创建存储过程
create procedure [dbo].[proLogin](
@i_name varchar(50),
@i_pwd varchar(50),
@o_re varchar(50) output) --返回信息
as
declare @co int; --查到总行数变量
begin
-- set @co=( select count(*) from student
-- where stuName=@i_name and stuPwd=@i_pwd);
select @co=count(*) from student
where stuName=@i_name and stuPwd=@i_pwd;
if @co = 1
begin
set @o_re='用户'+@i_name+'登陆成功!';
return 11;
end;
else
begin
set @o_re='用户'+@i_name+'登陆失败!';
return 22;
end;
end;
--测试存储过程
declare
@return_value int,
@o_re varchar(50)
exec @return_value=proLogin
@i_name = N'张三',
@i_pwd = N'123',
@o_re = @o_re OUTPUT
select @o_re,@return_value
=======前台程序代码======================
1、在Web.config配置登陆信息
<connectionStrings>
<add name="字符串名称" connectionString="server=服务器地址;database=数据库名称;uid=登陆名;pwd=密码;"/>
</connectionStrings>
2、前台Login.aspx
3、后台代码Login.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
namespace WebApplication1
{
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void btnLogin_Click(object sender, EventArgs e)
{
//用户名和密码可以从外部输入
string name = txtName.Text.Trim(); ;
string pwd = txtPwd.Text.Trim();
string strConn = System.Configuration.ConfigurationManager.ConnectionStrings["LinkSqlServer1"].ToString();
SqlConnection conn = new SqlConnection(strConn);
conn.Close();
SqlCommand cmd = new SqlCommand("proLogin", conn);
cmd.CommandType = CommandType.StoredProcedure;
//参数
SqlParameter pName = new SqlParameter("@i_name", SqlDbType.VarChar, 50);
pName.Value = name;
pName.Direction = ParameterDirection.Input;
SqlParameter pPwd = new SqlParameter("@i_pwd", SqlDbType.VarChar, 50);
pPwd.Value = pwd;
pPwd.Direction = ParameterDirection.Input;
//输出
SqlParameter pRe = new SqlParameter("@o_re", SqlDbType.VarChar, 50);
pRe.Direction = ParameterDirection.Output;
cmd.Parameters.Add(pName);
cmd.Parameters.Add(pPwd);
cmd.Parameters.Add(pRe);
conn.Open();
cmd.ExecuteNonQuery();
ScriptManager.RegisterStartupScript(this.btnLogin, btnLogin.GetType(),
"re", "alert('" + pRe.Value.ToString() + "');", true);
conn.Close();
}
}
}
CSharp SQLServer 登陆的更多相关文章
- CSharp Oracle 登陆
=======后台Oracle存储过程================ 1.创建表 --判读表存在先删除begin EXECUTE IMMEDIATE 'DROP TABLE student'; ...
- SQLserver登陆报错
https://blog.csdn.net/captain618/article/details/52331372 今天也不知道sql server抽了什么风,无论是windows登录还是sa登录,登 ...
- sqlserver 2005 分布式架构 对等事务复制 .
http://www.cnblogs.com/qanholas/archive/2012/03/22/2412444.html 一.为什么要使用对等事务复制 首先要说明的是使用sqlserve ...
- 提高SqlServer数据库的安全性,禁用掉sa账户
Sqlsever 数据库有两种登陆身份验证模式,一种是windows身份验证:一种是sqlserver 账户验证模式,在sqlserver 账户验证模式中,sa账户是大家所熟知的,并且sa也是内置的默 ...
- sql 2000 无法连接远程数据库 sqlserver不存在或访问被拒绝、不能打开到主机的连接,在端口1433:连接失败等 解决方案
问题: sql 2000 无法连接远程数据库 sqlserver不存在或访问被拒绝 telnet 127.0.0.1 1433 提示:不能打开到主机的连接,在端口1433:连接失败 解决方案: ...
- 阿里云ECS安装sqlserver,本地无法连接问题排查思路
1. 阿里云控制台-对应的ECS实例的安全组是否添加了响应的端口(1433)可以访问: 2. 服务器-sqlserver服务是否开启: 3. 服务器-sqlserver配置器,对应的端口是否启用,已经 ...
- SQLServer —— 用户权限操作
说明 以下操作都是基于SQLServer登陆验证方式登陆.而且操作员都是 sa. 一.添加登陆账号 use master go ' 第一个(xu)是登陆名,第二个(123456)是登陆密码. 执行语句 ...
- C# 常用数据库连接字符串【转】
一:C# 连接SQL数据库 Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myP ...
- C# 连接SQL数据库 常用连接字符串
一:C# 连接SQL数据库 Data Source=myServerAddress;Initial Catalog=myDataBase;User Id=myUsername;Password=myP ...
随机推荐
- jquery 设置select的默认值
<select id="sel" > <option value="s1" > aaaa </option> <opt ...
- MySQL 关闭FOREIGN_KEY_CHECKS检查
SET FOREIGN_KEY_CHECKS=0; truncate table QRTZ_BLOB_TRIGGERS; truncate table QRTZ_CALENDARS; truncate ...
- Android 表格布局<TableLayout>
表格布局即,tableLayout,表格布局通过行.列的形式来管理UI组件,TablelLayout并不需要明确地声明包含多少行.多少列,而是通过TableRow,以及其他组件来控制表格的行数和列数, ...
- queue C++
#include <iostream> using namespace std; class DequeEmptyException { public: DequeEmptyExcepti ...
- sql server数据库保存图片或者其他小文件
原文:sql server数据库保存图片或者其他小文件 测试用sql server数据库保存图片或者其他小文件. 文件流字段用varbinary类型. static void Main() { App ...
- graphterm 0.40.1 : Python Package Index
graphterm 0.40.1 : Python Package Index graphterm 0.40.1 Downloads ↓ A Graphical Terminal Interface ...
- 最经常使用的两种C++序列化方案的使用心得(protobuf和boost serialization)
导读 1. 什么是序列化? 2. 为什么要序列化?优点在哪里? 3. C++对象序列化的四种方法 4. 最经常使用的两种序列化方案使用心得 正文 1. 什么是序列化? 程序猿在编写应用程序的时候往往须 ...
- POJ1182 食物链 【并查集变种】
挺简单的 N个元素扩展为 3*N个 i-A i-B i-C A吃B吃C吃A 挑战程序设计的89面 #include <cstdio> #include <cstdlib> #i ...
- Web Api 2(Cors)Ajax跨域访问
支持Ajax跨域访问ASP.NET Web Api 2(Cors)的简单示例教程演示 随着深入使用ASP.NET Web Api,我们可能会在项目中考虑将前端的业务分得更细.比如前端项目使用Ang ...
- WPF案例 (三) 模拟QQ“快速换装"界面
原文:WPF案例 (三) 模拟QQ"快速换装"界面 这个小程序使用Wpf模拟QQ快速换装页面的动画特效,通过使用组合快捷键Ctrl+Left或Ctrl+Right,可实现Image ...