

create table tb_login
(
lid int identity( 1 , 1 ) primary key,
lName nvarchar( 30 ) not null ,
lPwd nvarchar( 30 ) not null ,
lPurview int default ( 3 )
)
go
insert into tb_login
select ' admin ' , ' admin123 ' , 2 union
select ' marry ' , ' marry123 ' ,
go
create table tb_userInfo
(
uid int identity( 1 , 1 ) primary key,
uName nvarchar( 30 ) not null ,
uAge int ,
uCardNum char ( 18 ),
uDescription nvarchar( 50 )
)
go
insert into tb_userInfo
select ' 刘德华 ' , 43 , ' 123456789012345678 ' , ' 歌星,演员 ' union
select ' 任贤齐 ' , 40 , ' 123456789012345679 ' , ' 歌星 ' union
select ' 韩寒 ' , 29 , ' 1234567890123456780 ' , ' 作家 '
go
name = " conString " connectionString = " Data Source=.;Initial Catalog=BRTData_guangzhou;Persist Security Info=True;User ID=sa;Password=sa "
public static string connectionString = ConfigurationManager.ConnectionStrings[ " conString " ].ConnectionString;
private SqlConnection conn;
private SqlCommand com;
// 根据条件查询
public List < userInfoModel > GetUserInfoAll()
{
List < userInfoModel > list = new List < userInfoModel > ();
UserInfoModel userInfo;
using (conn = new SqlConnection( " conString " ))
{
if (conn.State != ConnectionState.open)
conn.open();
com = new Sqlcommand( "" ,conn)
com.CommandType = CommandType.storeProcedure
SqlParameter[] spt = new SqlParameter[]
{
new SqlParameter( " @num " ,SqlDbType.Int, 4 );
...
};
// 标记输出参数
sqlPmr[ 0 ].Direction = ParameterDirection.Output;
...
com.Parameters.AddRange(sqlPmr);
// 获取输出参数
com.ExecuteNonQuery();
num = Convert.ToInt32 (com.Parameters[ " @num " ].Value);
using (SqlDateReader sdr = com.ExecuteReader)
{
while (sdr.Read())
userInfo = new UserInfoModel();
.....
list.add(userInfo);
}
}
return list;
}
// 插入数据
public void InsertUserInfo(userInfoModel userInfo)
{
using (conn = new SqlConnection( " conString " ))
{
if (conn.State != ConnectionState.open)
conn.open();
com = new Sqlcommand( "" ,conn)
com.CommandType = CommandType.storeProcedure
SqlParameter[] spt = new SqlParameter[]
{
new SqlParameter( " @num " ,SqlDbType.Int, 4 ),
new SqlParameter( " @num1 " ,SqlDbType.Int, 4 ),
.....
};
sqlPmr[ 0 ].Value = userInfo.uName;
.....
com.Parameters.AddRange(sqlPmr);
com.ExecuteNonQurey();
}
}
(
lid int identity( 1 , 1 ) primary key,
lName nvarchar( 30 ) not null ,
lPwd nvarchar( 30 ) not null ,
lPurview int default ( 3 )
)
go
insert into tb_login
select ' admin ' , ' admin123 ' , 2 union
select ' marry ' , ' marry123 ' ,
go
create table tb_userInfo
(
uid int identity( 1 , 1 ) primary key,
uName nvarchar( 30 ) not null ,
uAge int ,
uCardNum char ( 18 ),
uDescription nvarchar( 50 )
)
go
insert into tb_userInfo
select ' 刘德华 ' , 43 , ' 123456789012345678 ' , ' 歌星,演员 ' union
select ' 任贤齐 ' , 40 , ' 123456789012345679 ' , ' 歌星 ' union
select ' 韩寒 ' , 29 , ' 1234567890123456780 ' , ' 作家 '
go
name = " conString " connectionString = " Data Source=.;Initial Catalog=BRTData_guangzhou;Persist Security Info=True;User ID=sa;Password=sa "
public static string connectionString = ConfigurationManager.ConnectionStrings[ " conString " ].ConnectionString;
private SqlConnection conn;
private SqlCommand com;
// 根据条件查询
public List < userInfoModel > GetUserInfoAll()
{
List < userInfoModel > list = new List < userInfoModel > ();
UserInfoModel userInfo;
using (conn = new SqlConnection( " conString " ))
{
if (conn.State != ConnectionState.open)
conn.open();
com = new Sqlcommand( "" ,conn)
com.CommandType = CommandType.storeProcedure
SqlParameter[] spt = new SqlParameter[]
{
new SqlParameter( " @num " ,SqlDbType.Int, 4 );
...
};
// 标记输出参数
sqlPmr[ 0 ].Direction = ParameterDirection.Output;
...
com.Parameters.AddRange(sqlPmr);
// 获取输出参数
com.ExecuteNonQuery();
num = Convert.ToInt32 (com.Parameters[ " @num " ].Value);
using (SqlDateReader sdr = com.ExecuteReader)
{
while (sdr.Read())
userInfo = new UserInfoModel();
.....
list.add(userInfo);
}
}
return list;
}
// 插入数据
public void InsertUserInfo(userInfoModel userInfo)
{
using (conn = new SqlConnection( " conString " ))
{
if (conn.State != ConnectionState.open)
conn.open();
com = new Sqlcommand( "" ,conn)
com.CommandType = CommandType.storeProcedure
SqlParameter[] spt = new SqlParameter[]
{
new SqlParameter( " @num " ,SqlDbType.Int, 4 ),
new SqlParameter( " @num1 " ,SqlDbType.Int, 4 ),
.....
};
sqlPmr[ 0 ].Value = userInfo.uName;
.....
com.Parameters.AddRange(sqlPmr);
com.ExecuteNonQurey();
}
}