页面生成的两种方式
可以通过ASP.NET程序来生成
(1)在程序中拼接字符串。将要展示的页面Html代码标签写入到字符串中,然后
一,建立Study_ASPNET数据库
设置数据库用户名:sa 密码:123456
后期需用到
create Database Study_ASPNET
go
USE Study_ASPNET
go
create table EmployeeInfo(
ID int IDENTITY(1,1) NOT NULL Primary Key,
[Name][nvarchar](32) NOT NULL,
[Age] [tinyint] NULL,
[Phone][nchar](11)NULL,
[Company][nvarchar](32)NULL,
[Adress][nvarchar](32)NULL
)
go
insert into EmployeeInfo values('小新1号',20,'20191230001','百度','北京')
insert into EmployeeInfo values('小新2号',20,'20191230001','网易','北京')
insert into EmployeeInfo values('小新3号',20,'20191230001','淘宝','北京')
insert into EmployeeInfo values('小新4号',20,'20191230001','拼多多','北京')
select* from EmployeeInfo
二,打开Visual studio
新建项目
SqlHelper.cs文件
记得把复制粘贴的SqlHelper.cs文件中的命名空间改成与项目相同的命名空间
using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
namespace EmployeeInfoManage1
{
public static class SqlHelper
{
private static string conStr = System.Configuration.ConfigurationManager.ConnectionStrings["conStr"].ConnectionString;
public static int ExcuteNonQuery(string sql, params SqlParameter[] pms)
{
int count = 0;
using(SqlConnection con = new SqlConnection(conStr))
{
using (SqlCommand cmd = new SqlCommand(sql,con))
{
if(pms !=null)
{
cmd.Parameters.AddRange(pms);
}
con.Open();
count = cmd.ExecuteNonQuery();
}
}
return count;
}
public static object ExcuteScalar(string sql, params SqlParameter[] pms)
{
int count = 0;
using (SqlConnection con = new SqlConnection(conStr))
{
using (SqlCommand cmd = new SqlCommand(sql, con))
{
if (pms != null)
{
cmd.Parameters.AddRange(pms);
}
con.Open();
return cmd.ExecuteScalar();
}
}
}
public static SqlDataReader ExcuteReader(string sql, params SqlParameter[] pms)
{
SqlConnection con = new SqlConnection(conStr);
using (SqlCommand cmd = new SqlCommand(sql, con))
{
if (pms != null)
{
cmd.Parameters.AddRange(pms);
}
try
{
con.Open();
return cmd.ExecuteReader(CommandBehavior.CloseConnection);
}
catch (Exception)
{
con.Close();
con.Dispose();
throw;
}
}
}
public static DataTable ExcuteDataTable(string sql, params SqlParameter[] pms)
{
DataTable dt = new DataTable();
using (SqlDataAdapter sda = new SqlDataAdapter(sql, conStr))//外侧代码-using
{
if (pms != null)
{
sda.SelectCommand.Parameters.AddRange(pms);
}
sda.Fill(dt);
}
return dt;
}
}
}
修改web.config文件
添加
<connectionStrings>
<add name="conStr"
connectionString="server=.;uid=sa;pwd=123456;database=Study_ASPNET"/>
</connectionStrings>
<?xml version="1.0" encoding=&