让存储过程可以插入空值

 


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

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


表现层
 1 None.gif          public   void  BindContent()
 2 ExpandedBlockStart.gifContractedBlock.gif         dot.gif {
 3InBlock.gif            FirstName.Text = this.user.FirstName;
 4InBlock.gif            EmailAddress.Text = this.user.EmailAddress;
 5InBlock.gif            LastName.Text = this.user.LastName;
 6InBlock.gif            Address1.Text = this.user.Address1;
 7InBlock.gif            Address2.Text = this.user.Address2;
 8InBlock.gif            ZipCode.Text = this.user.ZipCode;
 9InBlock.gif            City.Text = this.user.City;
10InBlock.gif            HomePhone.Text = this.user.HomePhone;
11InBlock.gif            State.Text = this.user.State;
12InBlock.gif
13InBlock.gif            this.BindUserRoles();
14ExpandedBlockEnd.gif        }

转载于:https://www.cnblogs.com/huang/archive/2006/03/04/342605.html

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值