【问题标题】:Display an id from database column before the id is actually created在实际创建 id 之前显示数据库列中的 id
【发布时间】:2016-03-27 12:06:52
【问题描述】:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using HRMSController;
using HRMSBusinessEntities;
using System.Data;


namespace HumanResourceManagementSystems
{
    public partial class HRMSEmployee : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string username = (string)(Session["LoginUser"]);
            if (Session["LoginUser"] != null)
            {
                lblDisplay.Text = "Welcome..." + username;
            }
            Calendar1.Visible = false;
            Label1.Visible = false;
            txtcurrdate.Text = System.DateTime.Now.ToLongDateString();
        }

        protected void Btnmodified_Click(object sender, EventArgs e)
        {
            Calendar1.Visible = true;

        }
        protected void Add_Click(object sender, EventArgs e)
        {
            EmployeeEntity record = new EmployeeEntity
            {
                name = txtname.Text,
                currentdate = Convert.ToDateTime(txtcurrdate.Text),
                modifieddate = Convert.ToDateTime(txtmodifieddate.Text)
            };
            EmployeeController add = new EmployeeController();
            add.Add(record);
            Label1.Visible = true;
            Label1.Text = "Added" ;
            Clear();


        }
        public void Clear()
        {
            txtname.Text = "";
            txtcurrdate.Text = "";
            txtmodifieddate.Text = "";
        }

        protected void Calendar1_SelectionChanged(object sender, EventArgs e)
        {
            txtmodifieddate.Text = Calendar1.SelectedDate.ToString();
        }

        protected void Button3_Click(object sender, EventArgs e)
        {
            Clear();
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            Calendar1.Visible = true;
        }
    }


}

我在 Visual Studio 2010 中创建了一个用于插入员工详细信息的页面。当我单击添加时,它显示为已添加,并且 id 在后端自动增加。但是如果我必须显示为 ( "你的 EMP ID 是某个数字(eg.10) ) 在执行时在前端,我该怎么办?

【问题讨论】:

  • 当我插入员工详细信息并单击添加按钮时,它不应显示为已添加,而是应显示为您的员工 ID 为 10(或某个数字)。代码应该是什么我将其包含在我现有的代码中吗? @大卫
  • 那么我想你会想修改这行代码:Label1.Text = "Added"; 你有没有尝试过什么?如果您想将文本“已添加”更改为其他内容,那么看起来非常明显会发生这种情况。
  • 我们对代码进行了更改,但它需要显示员工 ID 号以及文本示例:Label1.Text = "Added" ===> Label1.Text = " 您的员工 ID 是" 10(它应该显示这个数字 10。但我们不知道如何显示@David
  • raghav,您知道添加时的实际员工 ID 是什么吗?它是通过调用 EmployeeController 中的 Add 方法返回的吗?
  • 没有员工 ID 自己生成。我们在后端 sql server 2008 中为员工 ID 提供了身份。@LarsKristensen

标签: c# asp.net visual-studio-2010 exception frontend


【解决方案1】:

我认为在用户仍在创建员工时显示员工 ID 不是一个好主意。

假设用户 1 在页面中徘徊,花时间创建新员工,可能有其他用户(用户 2)也在同时尝试创建员工。用户 2 已经创建了员工,而用户 1 仍然没有吨。因此,在创建时显示员工会产生歧义,因为在当前用户创建员工时可能已经创建了许多其他员工。

因此,在用户创建完员工后,最好在标签中向用户显示员工 ID。

label1.text="Employee succesfully added"+getemployeeid();

public string getemployeeid(){return yourobject.hitTheDataBaseMethod().tostring();};

【讨论】:

    猜你喜欢
    • 2014-11-17
    • 2012-06-24
    • 1970-01-01
    • 1970-01-01
    • 2018-06-07
    • 2019-05-13
    • 2018-11-13
    • 1970-01-01
    • 2020-01-23
    相关资源
    最近更新 更多