在将数据绑定到详细信息视图之前如何验证数据库中的字段
如何在将数据库中的字段绑定到详细信息视图之前验证它们
我有一些字段需要在进入详细信息视图之前进行验证,
例如,应该消除空值字段。 ..并且需要
为该表中的外键字段获取更多数据(即在其他表中具有数据)
我想我可以在 ondatabinding 事件中执行此操作...
protected void dvDataBinding(object sender,事件参数 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;
}
提前致谢
how to validate fields from DB before binding them to details view
I have some fields which needs to be validated before going into the details view
For Eg null valued fields should be eleminated ... and need to get some more data for the
fields which are foreign keys in this table (ie have the data in other table )
i thought i can do this in ondatabinding event ...
protected void dvDataBinding(object sender, EventArgs e)
{
}
in the following function i will pass the req_ID..
data binding in details view ...
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;
}
Thanks in advance
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为什么您希望在绑定时删除数据,为什么不在 GetExceptionDataDetailedView 返回数据之前从数据集中删除数据。这样您就不必担心详细信息视图,因为它只会绑定到正确的数据。另外,为什么要查找外键,正确的方法是在 sql 语句中创建与外部表的连接,并使用外部表中的相关字段。
Why do you wish to remove data wen you are binding, why not remove the data from the dataset before it is returned by GetExceptionDataDetailedView. That way you don't ave to worry about the details view as it will only bind to the correct data. also why would you want to lookup foreign keys, the correct way would be to create a join in your sql statement to the foreign table and use the relevent field from the foreign table.