本文介绍了C Sharp Textbox显示“& nbsp;”为空值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如果找不到任何数据视图,if函数代码中的以下代码适用于save。它找到任何数据视图然后转到其他部分并编辑数据。但问题是,当我想看到备注的文字时,它会显示 。我怎样才能得到它的空值。我的意思是txtRemark没有显示任何数据。
private void SaveDataFotblMaintenancePlanDate()
{
DataTable DTLocal = null ;
DataView DVLocal = null ;
DataRow DRLocal = null ;
System.Web.UI.Page this_page_ref = null ;
string strSQL = null ;
尝试
{
DTLocal = 新 DataTable ();
DVLocal = new DataView();
for ( int i = 0 ; i < grdEdit.Rows.Count; i ++)
{
// strSQL =select * from tblMaintenancePlanDate where MPDCode ='+ txtMPDCode.Text.Trim()+';
strSQL = 从tblMaintenancePlanDate中选择*其中MPCode =' + txtMPCode.Text.Trim()+ ';
ConManager.DBConnection( TERMSMNT);
ConManager.OpenDataTableThroughAdapter(strSQL, out DTLocal, true );
DTLocal.TableName = MaintenanceDates;
DVLocal.Table = DTLocal;
if (DVLocal.Count == 0 )
{
NewMPDateCode();
DRLocal = DTLocal.NewRow();
DRLocal [ MPDCode] = txtMPDCode.Text.Trim();
DRLocal [ SheduleDate] = Convert.ToDateTime(grdEdit.Rows [i]。单元格[ 1 ]。文本);
DRLocal [ MPCode] =会话[ USER]。ToString()。Trim();
DRLocal [ 备注] = ;
DTLocal.Rows.Add(DRLocal);
txtMPDCode.Text = ;
}
else
{
DRLocal = DVLocal [ 0 跨度>]行。
DRLocal.BeginEdit();
if (txtSheduleDate.Text!= )
DRLocal [ SheduleDate] =转换.ToDateTime(txtSheduleDate.Text.Trim());
if (txtRemark.Text!= )
DRLocal [ 备注] = txtRemark.Text.Trim ();
if (txtMPDCode.Text!= )
DRLocal [ MPDCode] = txtMaintenanceSheduleCode.Text.Trim ();
DRLocal [ MPCode] = txtMPCode.Text.Trim();
DRLocal.EndEdit();
}
ConManager.DBConnection( TERMSMNT);
ConManager.BeginTransaction();
ConManager.SaveDataTableThroughAdapter( ref DTLocal, true );
ConManager.CommitTransaction();
}
}
catch (例外情况)
{
throw ex;
}
finally
{
ConManager.CloseConnection();
}
}
解决方案
In the following code in the if function codes work for save if it does not find any data view. It it finds any dataviews then it goes to else portion and edit the data. But the problem is that when I want to see the text for remarks it shows " ". How can I get it empty value. I mean the txtRemark does not show any data.
private void SaveDataFotblMaintenancePlanDate() { DataTable DTLocal = null; DataView DVLocal = null; DataRow DRLocal = null; System.Web.UI.Page this_page_ref = null; string strSQL = null; try { DTLocal = new DataTable(); DVLocal = new DataView(); for (int i = 0; i < grdEdit.Rows.Count; i++) { //strSQL = "Select * from tblMaintenancePlanDate where MPDCode = '" + txtMPDCode.Text.Trim() + "'"; strSQL = "Select * from tblMaintenancePlanDate where MPCode = '" + txtMPCode.Text.Trim() + "'"; ConManager.DBConnection("TERMSMNT"); ConManager.OpenDataTableThroughAdapter(strSQL, out DTLocal, true); DTLocal.TableName = "MaintenanceDates"; DVLocal.Table = DTLocal; if (DVLocal.Count == 0) { NewMPDateCode(); DRLocal = DTLocal.NewRow(); DRLocal["MPDCode"] = txtMPDCode.Text.Trim(); DRLocal["SheduleDate"] = Convert.ToDateTime(grdEdit.Rows[i].Cells[1].Text); DRLocal["MPCode"] = Session["USER"].ToString().Trim(); DRLocal["Remarks"] = ""; DTLocal.Rows.Add(DRLocal); txtMPDCode.Text = ""; } else { DRLocal = DVLocal[0].Row; DRLocal.BeginEdit(); if (txtSheduleDate.Text != "") DRLocal["SheduleDate"] = Convert.ToDateTime(txtSheduleDate.Text.Trim()); if (txtRemark.Text != "") DRLocal["Remarks"] = txtRemark.Text.Trim(); if (txtMPDCode.Text != "") DRLocal["MPDCode"] = txtMaintenanceSheduleCode.Text.Trim(); DRLocal["MPCode"] = txtMPCode.Text.Trim(); DRLocal.EndEdit(); } ConManager.DBConnection("TERMSMNT"); ConManager.BeginTransaction(); ConManager.SaveDataTableThroughAdapter(ref DTLocal, true); ConManager.CommitTransaction(); } } catch (Exception ex) { throw ex; } finally { ConManager.CloseConnection(); } }
解决方案
这篇关于C Sharp Textbox显示“& nbsp;”为空值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!