日期:2014-05-20  浏览次数:21200 次

dataset更新数据库,急~~~!
this.pub_CorpInfoTableAdapter.Fill(this.db_Mis_mhDataSet_Pub_CorpInfo.Pub_CorpInfo);//在load中填充数据集    
DataRow     NewCorpInfo     =     db_Mis_mhDataSet_Pub_CorpInfo.Pub_CorpInfo.NewRow();    
NewCorpInfo[ "CorpName "]     =     this.tbxCorpName.Text;    
NewCorpInfo[ "ECorpName "]     =     this.tbxECorpName.Text;    
NewCorpInfo[ "PostalCode "]     =     this.tbxPostalCode.text;    
                                                              this.pub_CorpInfoTableAdapter.Update(this.db_Mis_mhDataSet_Pub_CorpInfo.Pub_CorpInfo);//更新数据库    
 
为什么更新不了!    
 
另外数据库中PostalCode字段可以为空,但是如果tbxPostalCode的值不填,就出现异常提示“输入字符串的格式不正确。不能在     PostalCode     列中存储     <> 。所需类型是     Int32。”    
 
急~!!!    
在线等待!!!

------解决方案--------------------
DataTable dt1 = new DataTable();

dt1.Columns.Add( "id ");
dt1.Columns.Add( "carId ");
dt1.Columns.Add( "picName ");
dt1.Columns.Add( "picSize ");
dt1.Columns.Add( "picMemo ");
dt1.Columns.Add( "CarNum ");
dt1.Columns.Add( "PgPrice ");

DataRow dr = dt1.NewRow();

dr[ "id "] = dr1[ "id "];
dr[ "carId "] = dr1[ "carId "];
dr[ "picName "] = dr1[ "picName "];
dr[ "picSize "] = dr1[ "picSize "];
dr[ "picMemo "] = dr1[ "picMemo "];
dr[ "CarNum "] = dr1[ "CarNum "];
dr[ "PgPrice "] = dr1[ "PgPrice "];

dt1.Rows.Add(dr);
------解决方案--------------------
插入之前判断文本框的值,如果为空,则赋值System.DBNull.Value