[英]How to validate which data (rows) to load to a DB from a table in excel?
[英]how to validate fields from DB before binding the data to the details view
在綁定到詳細信息視圖之前如何驗證數據庫中的字段
在進入詳細信息視圖之前,我需要驗證一些字段
例如,應清除空值字段,並且需要獲取更多數據
在此表中為外鍵的字段(即在其他表中具有數據)
我以為我可以在ondatabinding事件中做到這一點...
受保護的void dvDataBinding(對象發送者,EventArgs e){}
在以下函數中,我將傳遞req_ID。
細節視圖中的數據綁定...
public DataSet GetExceptionDataDetailedView(string strWorkRequestID)
{
DBManager objDBManager = new DBManager();
StringBuilder strSQL = new StringBuilder();
StringBuilder strColName = new StringBuilder(); //string strTableField;
DataSet objDataSet;
try
{
strSQL.Append("SELECT * FROM work_request where work_request_id='");
strSQL.Append(strWorkRequestID);
strSQL.Append("'");
// Open the connection object
objConnection = objDBManager.OpenDBConnection();
//Create a command object to execute the Store procedure
objCommand = new MySqlCommand();
objCommand.CommandText = strSQL.ToString();
objCommand.CommandType = CommandType.Text;
objCommand.Connection = objConnection;
MySqlDataAdapter objDataAdapter = new MySqlDataAdapter(objCommand);
objDataSet = new DataSet();
objDataSet.Tables.Clear();
objDataAdapter.Fill(objDataSet);
}
catch (MySqlException exSQL)
{
throw exSQL;
}
catch (Exception exGeneral)
{
throw exGeneral;
}
finally
{
//close the connection object
objDBManager.CloseDBConnection();
}
return objDataSet;
}
提前致謝
為什么要在綁定時刪除數據,為什么不在GetExceptionDataDetailedView返回數據集之前從數據集中刪除數據。 這樣,您就不必擔心細節視圖,因為它只會綁定到正確的數據。 還有為什么要查找外鍵,正確的方法是在sql語句中創建到外表的聯接,並使用外表中的relevent字段。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.