mvc 02

9:工具类如何写一个增删改的方法?

public static int ExecuteNonQuery(string sql)
        {
            //创建数据库连接
            SqlConnection conn = new SqlConnection(strConn);
 
            try
            {
                //打开数据库
                conn.Open();
                //创建Command命令
                SqlCommand comm = new SqlCommand(sql, conn);
                //返回结果
                return comm.ExecuteNonQuery();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                //关闭数据库连接
                conn.Close();
            }
        } 

10:如何写向表里面插入一条记录的sql? 

insert 表名(列)values(值)

11:怎么查询一张表的记录?

select * from 表名

12:Ajax的提交格式?

$.ajax({
    url:"../regionservlet",//数据请求的地址
    data:{"paid":-1},//返回给客户端的json数据
    dataType:"json",//数据类型格式
    type:"post",//ajax数据访问的方法
    success:function(){
    }
})

13:工具类如何写一个查询的方法?

 public static object ExecuteScalar(string sql)
        {
            //创建数据库连接
            SqlConnection conn = new SqlConnection(strConn);
 
            try
            {
                //打开数据库
                conn.Open();
                //创建Command命令
                SqlCommand comm = new SqlCommand(sql, conn);
                //返回结果
                return comm.ExecuteScalar();
            }
            catch (Exception)
            {
                throw;
            }
            finally
            {
                //关闭数据库连接
                conn.Close();
            }
        }


14:如何引入第三方类库?

引用右键添加引用 在右下脚有个浏览 点击找到第三方类库

15:第三方的项目Remote

在appSettings里面添加 存储<add key="k" value="v" />    读取ConfigurationManager.AppSettings["k"]

16:WebConfig如何配置变量的值? 后台如何读取?

public static DataView BindingView(string sql)
        {
            DataSet ds = new DataSet();
            //准备SQL语句--从外界传过来
            //准备数据库适配器
            SqlDataAdapter sda = new SqlDataAdapter(sql, DBHelper.Connection);
            //填充数据
            sda.Fill(ds);
            //创建DataView
            DataView dv = new DataView(ds.Tables[0]);
            //返回数据
            return dv;
        }

17:工具类如何写一个数据集的方法? 

public static DataView BindingView(string sql)
        {
            DataSet ds = new DataSet();
            //准备SQL语句--从外界传过来
            //准备数据库适配器
            SqlDataAdapter sda = new SqlDataAdapter(sql, DBHelper.Connection);
            //填充数据
            sda.Fill(ds);
            //创建DataView
            DataView dv = new DataView(ds.Tables[0]);
            //返回数据
            return dv;
        }

18:数据集如何转换成List<T> [知识点:反射]

public IList <T> GetList <T>(DataTable table)   
  {   
  IList <T> list = new List <T>();   
  T t = default(T);   
  PropertyInfo[] propertypes = null;   
  string tempName = string.Empty;   
  foreach (DataRow row in table.Rows)   
  {   
  t = Activator.CreateInstance <T>();   
  propertypes = t.GetType().GetProperties();   
  foreach (PropertyInfo pro in propertypes)   
  {   
  tempName = pro.Name;   
  if (table.Columns.Contains(tempName))   
  {   
  object value = row[tempName];   
  pro.SetValue(t, value, null);   
  }   
  }   
  list.Add(t);   
  }   
  return list;   
  } 

 19:什么Cookie?什么是Session? 两者有什么区别?

Cookie存储在客户端的   Session存储在每次绘画种关闭就没有了 


20:Cookie和Session的使用?

//使用cookie
                    HttpCookie cookie = new HttpCookie("KEY");
                    cookie["KEY"] = "值";
                    System.Web.HttpContext.Current.Response.Cookies.Add(cookie);
//使用Session
                    HttpContext.Session["KEY"] = VALUE;

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值