zoukankan      html  css  js  c++  java
  • sql 的数据类型

    设字段为 uniqueidentifier 显示为32位的二进制的编码;好处是当几个系统进行整和时id不会发生冲突;8-4-4-4-12组合;

    public static Agent CreateAgent(Agent agent)
      {
       IConnection cnn = ConnectionManager.GetConnection();
       cnn.Open();
       ITransaction trans = cnn.BeginTransaction();
       ICommand cmd;
       int i=0;
       int effectedRows = 0;

       Guid agentId = Guid.NewGuid();
       string sql = "INSERT INTO [B2B_Agent]( "
        + " [AgentId], [Code], [Type], [Level],  "
        + " [CompanyName], [CompanyNameShort], [ProvinceCode], [CityCode], "
        + " [Address], [PostCode], [Linkman], [Email], [Tel], "
        + " [MobileTel], [Msn], [QQ], [IsProvider], [IsPurchaser], [State], [RegisterDate], [Introducer], [CommisionMode]) "
        + " VALUES(  "
        + " ?, '', ?, ?, "
        + " ?, ?, ?, ?, "
        + " ?, ?, ?, ?, ?, "
        + " ?, ?, ?, ?, ?, ?, getdate(), '', ?) ";
       cmd = cnn.CreateCommand(sql);
       cmd.Transaction = trans;
       cmd.SetGuid(i, agentId); i++;
       cmd.SetInt(i, agent.Type); i++;
       cmd.SetInt(i, agent.Level); i++;
       cmd.SetNVarChar(i, agent.CompanyName); i++;
       cmd.SetNVarChar(i, agent.CompanyNameShort); i++;
       cmd.SetInt(i, agent.ProvinceCode); i++;
       cmd.SetInt(i, agent.CityCode); i++;
       cmd.SetNVarChar(i, agent.Address); i++;
       cmd.SetVarChar(i, agent.PostCode); i++;
       cmd.SetNVarChar(i, agent.Linkman); i++;
       cmd.SetVarChar(i, agent.Email);i++;
       cmd.SetVarChar(i, agent.Tel); i++;
       cmd.SetVarChar(i, agent.MobileTel); i++;
       cmd.SetVarChar(i, agent.Msn); i++;
       cmd.SetVarChar(i, agent.QQ); i++;
       cmd.SetBit(i, agent.IsProvider); i++;
       cmd.SetBit(i, agent.IsPurchaser); i++;
       cmd.SetInt(i, agent.State); i++;
       cmd.SetInt(i, agent.CommisionMode); i++;
       //cmd.SetBit(i, agent.IsProvider); i++;
       //cmd.SetBit(i, agent.IsPurchaser); i++;

       try
       {
        effectedRows = cmd.ExecuteNonQuery();
       }
       catch(Exception e)
       {
        goto Error;
       }
               
       if (!(effectedRows >0))
       {
        goto Error;
       }

       trans.Commit();
       cnn.Close();
       return GetAgentById(agentId);

       Error:
        trans.Rollback();
       cnn.Close();
       return null;

      } "?" 的作用是防止编码混乱;或者delete table1 where a=1 or 1=1

    declare @A varchar set@A='1 or 1=1'
    delete table1 where a=@A

  • 相关阅读:
    跨站脚本攻击—XSS
    ElasticSearch ClusterBlockException[blocked by: [FORBIDDEN/12/index read-only / allow delete (api)];
    mysql报Can't create/write to file '/tmp/ib0n3frL' (Errcode: 13
    Vue项目关闭ESLint + Prettier代码规范
    SpringBoot读取Resource下文件的几种方式
    elasticsearch5.6.1.集成springboot 遇到的坑
    如何利用XShell隧道通过跳板机连接内网机器
    重置windows10 WSL中ubuntu的密码
    【php】phpstorem201922破解版安装,亲测可以
    【死磕NIO】— 阻塞IO,非阻塞IO,IO复用,信号驱动IO,异步IO,这你真的分的清楚吗?
  • 原文地址:https://www.cnblogs.com/liufei88866/p/966018.html
Copyright © 2011-2022 走看看