【问题标题】:how to validate fields from DB before binding the data to the details view如何在将数据绑定到详细信息视图之前验证数据库中的字段
【发布时间】:2010-01-19 12:19:55
【问题描述】:

如何在将字段绑定到详细信息视图之前验证数据库中的字段

我有一些字段需要在进入详细信息视图之前进行验证

例如,空值字段应该被删除......并且需要为

获取更多数据

该表中的外键字段(即有其他表中的数据)

我认为我可以在 ondatabinding 事件中做到这一点......

protected void dvDataBinding(object sender, 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;
        }   

提前致谢

【问题讨论】:

  • 你的问题有点不清楚——你能说得更具体点吗?
  • 同意理查德,更多细节。你怎么绑定?对象数据源?还是您使用的是完全构建的 DAL/BLL 层?更多代码将帮助我们理解并帮助您。
  • iam 使用 mysql DB 并绑定数据 dvException.DataBind();这里 dvException 是细节视图

标签: c# detailsview


【解决方案1】:

为什么要在绑定时删除数据,为什么不在 GetExceptionDataDetailedView 返回之前从数据集中删除数据。这样您就不必担心详细信息视图,因为它只会绑定到正确的数据。还有你为什么要查找外键,正确的方法是在你的 sql 语句中创建一个连接到外部表并使用外部表中的相关字段。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-05-09
    • 1970-01-01
    • 2023-04-07
    • 2012-06-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多