9:工具类如何写一个增删改的方法?
public static int ExecuteNonQuery(string sql,SqlParameter[] sqlParameter)
{
//1:创建数据库连接
SqlConnection connection = new SqlConnection(connectionStr);
try
{
//2;打开数据库连接
connection.Open();
//第三步变成直接从外面传一个string变量
//4:生成Command对象
SqlCommand comm = new SqlCommand(sql, connection);
comm.Parameters.AddRange(sqlParameter);
//5:执行SQL语句
return comm.ExecuteNonQuery();
}
catch (Exception)
{
throw;
}
finally
{
//无论数据库操作成功或者失败,都要关闭数据库
//7;关闭数据库连接
connection.Close();
}
}
10:如何写向表里面插入一条记录的sql?
INSERT INTO 表名称 VALUES (值1, 值2,....)
11:怎么查询一张表的记录?
select * from 表名
12:Ajax的提交格式?
$.ajax({
url: "/Login/logins",
data: data,
type: "post",
success: function (json) {
if (json.Success) {
alert("登录成功!!");
location.href = "/Home/Index";
} else {
alert("登录失败!!");
}
}
})
13:工具类如何写一个查询的方法?
public static object ExecuteScalar(string sql,SqlParameter[] sqlParameters)
{
//1:创建数据库连接
SqlConnection connection = new SqlConnection(connectionStr);
try
{
//2;打开数据库连接
connection.Open();
//第三步变成直接从外面传一个string变量
//4:生成Command对象
SqlCommand comm = new SqlCommand(sql, connection);
comm.Parameters.AddRange(sqlParameters) ;
//5:执行SQL语句
return comm.ExecuteScalar();
}
catch (Exception)
{
throw;
}
finally
{
//无论数据库操作成功或者失败,都要关闭数据库
//7;关闭数据库连接
connection.Close();
}
}
14:如何引入第三方类库?
选中要引用的项目下的引用,右键点击选中管理NuGet程序包,输入你需要的类库名称
15:第三方的项目Remote
public class TenXunYunSMS
{
//appId
public int appId ;
//appKey
public string appKey = "";
//接收手机号
// string phoneNumber =
//短信模板ID
private int tmplateId = 379257;
//签名内容
private string smsSign = "7hhhcn";
private int RandomCode { get; set; } //短信
/// <summary>
/// 获取短信验证码
/// </summary>
/// <returns></returns>
private void Code()
{
Random random = new Random();
RandomCode = random.Next(10000, 99999);
}
public int SetSMS(string phone)
{
Code();//获取sj验证码
try
{
SmsSingleSender ssender = new SmsSingleSender(appId, appKey);
var result = ssender.sendWithParam("86", phone,
tmplateId, new[] { RandomCode.ToString() }, smsSign, "", ""); // 签名参数未提供或者为空时,会使用默认签名发送短信
Console.WriteLine(result);
}
catch (JSONException e)
{
Console.WriteLine(e);
}
catch (HTTPException e)
{
Console.WriteLine(e);
}
catch (Exception e)
{
Console.WriteLine(e);
}
return RandomCode;
}
}
16:WebConfig如何配置变量的值? 后台如何读取?
<add key="DBConn" value="server=192.168.1.1;Database=****;UID=*****;PWD=******;" />
String basePath = System.Configuration.ConfigurationManager.AppSettings["配置节点名称"].ToString();
17:工具类如何写一个数据集的方法?
public static List<T> DataTableToList<T>(DataTable dt)
{
List<T> list = new List<T>();
for (int i = 0; i < dt.Rows.Count; i++)
{
T type = Activator.CreateInstance<T>();
for (int j = 0; j < dt.Columns.Count; j++)
{
//获取当前type的所有属性集合
PropertyInfo[] propertyInfos = type.GetType().GetProperties();
foreach (PropertyInfo item in propertyInfos)
{
if (dt.Columns[j].ColumnName==item.Name)
{
if (dt.Rows[i][j]!=DBNull.Value)
{
item.SetValue(type, dt.Rows[i][j]);
}
}
}
}
list.Add(type);
}
return list;
}
18:数据集如何转换成List<T> [知识点:反射]
public static List<T> DataTableToList<T>(DataTable dt)
{
List<T> list = new List<T>();
for (int i = 0; i < dt.Rows.Count; i++)
{
T type = Activator.CreateInstance<T>();
for (int j = 0; j < dt.Columns.Count; j++)
{
//获取当前type的所有属性集合
PropertyInfo[] propertyInfos = type.GetType().GetProperties();
foreach (PropertyInfo item in propertyInfos)
{
if (dt.Columns[j].ColumnName==item.Name)
{
if (dt.Rows[i][j]!=DBNull.Value)
{
item.SetValue(type, dt.Rows[i][j]);
}
}
}
}
list.Add(type);
}
return list;
}
19:什么Cookie?什么是Session? 两者有什么区别?
cookie是Web服务器发送给浏览器的一块信息。
session是另一种记录客户状态的机制。
session对象是在服务器内存中的,而基于窗口的cookie是在客户端内存中的。
cookie不是很安全,别人可以分析存放在本地的cookie,进行cookie欺骗;session会在一定时间内保存在服务器上,当访问增多,会占用服务器性能
20:Cookie和Session的使用?
1、存储在服务端:通过cookie存储一个session_id,然后具体的数据则是保存在session中。如果用户已经登录,则服务器会在cookie中保存一个session_id,下次再次请求的时候,会把该session_id携带上来,服务器根据session_id在session库中获取用户的session数据。就能知道该用户到底是谁,以及之前保存的一些状态信息。这种专业术语叫做server side session。
2、将session数据加密,然后存储在cookie中。这种专业术语叫做client side session。flask采用的就是这种方式,但是也可以替换成其他形式。
21:什么是路由?如何配置路由?
22:控制器的方法如何返回一个Json对象
把返回值类型改为JsonResult
return json(对象)
3:Ajax如何接受Json对象并做判断
success: function (json) {
if (json.Success) {
alert("登录成功!!");
location.href = "/Home/Index";
} else {
alert("登录失败!!");
}
}
24:Ajax提交,Form表单需要注意什么问题
删除from表单
25:Sql语句参数化处理。
string sql = "select COUNT(1) from SMSInfo where TelSMS=@TelSMS";
SqlParameter[] sqlParameter ={
new SqlParameter()
{
DbType = System.Data.DbType.Int32,
ParameterName="@TelSMS",
Value=sms.TelSMS1
}
};