zoukankan      html  css  js  c++  java
  • 让存储过程可以插入空值

     


    数据库层存数据
     1            SqlParameter[] 
     2                parameters = {
     3                                 new SqlParameter("@EmailAddress", SqlDbType.VarChar, 255),
     4                                 new SqlParameter("@Password", SqlDbType.Binary, 100),
     5                                 new SqlParameter("@FirstName", SqlDbType.VarChar, 30),
     6                                 new SqlParameter("@LastName", SqlDbType.VarChar, 50),
     7                                 new SqlParameter("@Address1", SqlDbType.VarChar, 80),
     8                                 new SqlParameter("@Address2", SqlDbType.VarChar, 80),
     9                                 new SqlParameter("@City", SqlDbType.VarChar, 40),
    10                                 new SqlParameter("@State", SqlDbType.VarChar, 40),                                 
    11                                 new SqlParameter("@ZipCode", SqlDbType.VarChar, 20),
    12                                 new SqlParameter("@HomePhone", SqlDbType.VarChar, 20),
    13                                 new SqlParameter("@Country", SqlDbType.VarChar, 50),
    14                                 new SqlParameter("@UserID", SqlDbType.Int, 4)
    15                             }
    ;
    16
    17            parameters[0].Value = emailAddress;
    18            parameters[1].Value = password;
    19            parameters[2].Value = firstName;
    20            parameters[3].Value = lastName;
    21            parameters[4].Value = address1;
    22            //parameters[5].Value = DBNull.Value;
    23            parameters[5].Value = address2;
    24            parameters[6].Value = city;
    25            parameters[7].Value = state;
    26            parameters[8].Value = zipCode;
    27            parameters[9].Value = homePhone;
    28            parameters[10].Value = country;
    29            parameters[11].Direction = ParameterDirection.Output;

    上层取值
     1        //根据ID获取,回写对象
     2        private void LoadFromID()
     3        {
     4            Data.User dataUser = new Data.User( moduleSettings.ConnectionString );
     5            DataRow userRow = dataUser.Retrieve( userID );
     6
     7            firstName= (string)userRow["FirstName"];
     8            lastName = (string)userRow["LastName"];
     9            address1 = (string)userRow["Address1"];
    10            //address2 = (string)userRow["Address2"];
    11            address2 = (userRow["Address2"== DBNull.Value) ? null : userRow["Address2"].ToString();
    12            city     = (string)userRow["City"];
    13            state    = (string)userRow["State"];
    14            zipCode  = (string)userRow["ZipCode"];
    15            homePhone= (string)userRow["HomePhone"];
    16            emailAddress = (string)userRow["EmailAddress"];
    17            password = (byte[])userRow["Password"];
    18            country=(string)userRow["Country"];
    19        }


    表现层
     1        public void BindContent()
     2        {
     3            FirstName.Text = this.user.FirstName;
     4            EmailAddress.Text = this.user.EmailAddress;
     5            LastName.Text = this.user.LastName;
     6            Address1.Text = this.user.Address1;
     7            Address2.Text = this.user.Address2;
     8            ZipCode.Text = this.user.ZipCode;
     9            City.Text = this.user.City;
    10            HomePhone.Text = this.user.HomePhone;
    11            State.Text = this.user.State;
    12
    13            this.BindUserRoles();
    14        }
  • 相关阅读:
    MySQL调优篇 | 逻辑架构解读(1)
    SQLPlus 在连接时通常有四种方式
    Oracle解决索引碎片功能
    windows2003 ftp 无法下载 解决
    bat记录
    ACCESS字符串操作函数
    缓存和RAID如何提高磁盘IO性能
    TortoiseSVN 命令 (命令行执行工具)
    在RHEL5下实现磁盘分区和磁盘配额
    PS 命令详解
  • 原文地址:https://www.cnblogs.com/huang/p/342605.html
Copyright © 2011-2022 走看看