获取空值,但是在重新启动应用程序时正确获取值 [英] Getting null value but when restarting the application getting the values correctly

查看:48
本文介绍了获取空值,但是在重新启动应用程序时正确获取值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我正在使用下面给出的代码,发生的是当我运行应用程序时我没有得到任何值,但是当我重新启动时我正确地得到了值,下面是绑定下拉列表的代码,当dtLeavetype有值时会发生什么,但是没有正确填充

Hi
I am using the code given below and what happens is when I run the application I didnt get any value but when i restart i am getting the values correctly and below is the code for binding the dropdown list what happens is when dtLeavetype has values but it is not getting populated correctly

private void bindLeaveStatus()
  {
      try
      {
          MySqlConnection con = new MySqlConnection(conn);
          con.Open();
          MySqlDataAdapter daLeaveType = new MySqlDataAdapter("select leave_type_id,leave_type from leave_type", con);
          DataTable dtLeavetype = new DataTable();
          daLeaveType.Fill(dtLeavetype);
          ddlLeaveType.DataTextField = "leave_type";
          ddlLeaveType.DataValueField = "leave_type_id";
          ddlLeaveType.DataSource = dtLeavetype;
          ddlLeaveType.DataBind();
          con.Close();
      }
      catch (Exception ex)
      {
          throw (ex);
      }
  }

推荐答案

我认为您应该检查的是启动应用程序与触发流程之间的区别.从已经运行的进程中.可能是您甚至在全新启动时都没有尝试从内部过程中检索数据.
I think what you should examine is the difference in process between what happens when you start your application as opposed to when you think you trigger the process from an already running process. It may be that you aren''t even trying to retrieve the data from the internal process while the fresh launch does.


我想;
1.您正在请假管理系统中加载请假类型.
2.请假类型存储在数据库的查找表中
3.例如,当您的ApplyForLeave.aspx文件或任何其他文件加载到浏览器中时,您想填充请假类型.

为此,理想的方案是

在页面加载时进行IsPostBack检查,然后调用函数

I am supposing;
1. You are loading leave types in a leave management system.
2. The leave types are stored in a look up table in the database
3. For example, when your ApplyForLeave.aspx file or any other file loads up in the browser, you would like to populate the leave types.

For this purpose, the ideal scenario would be

Put a IsPostBack check on page load and then call the function

page Load()
{
    if (!isPostBack)
    {
        bindLeaveStatus();
    }
}

 private void bindLeaveStatus()
    {
        try
        {
            MySqlConnection con = new MySqlConnection(conn);
            con.Open();
            MySqlDataAdapter daLeaveType = new MySqlDataAdapter("select leave_type_id,leave_type from leave_type", con);
            DataTable dtLeavetype = new DataTable();
            daLeaveType.Fill(dtLeavetype);
            ddlLeaveType.DataTextField = "leave_type";
            ddlLeaveType.DataValueField = "leave_type_id";
            ddlLeaveType.DataSource = dtLeavetype;
            ddlLeaveType.DataBind();
            con.Close();
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }



这将每次正确地使用休假类型加载您的下拉列表.

让我知道这是否使您感到困惑.

问候,
Nayan



This will correctly load your drop down list with the leave types every time.

Let me know if this confuses you.

Regards,
Nayan


这篇关于获取空值,但是在重新启动应用程序时正确获取值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆