商店ID在数据库中 [英] store ID's in the database

查看:62
本文介绍了商店ID在数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!我这里有一个小问题,我有以下主表





Hi! i have a slight problem here,I have the following master tables


M_employee

EMPID    Name 
1      abc
2      xyz
M_Division
DIVID  EMPID  DIVISON
1        2      arts
2        1      science
M_Designation
DESGID  EMPID  Designation
1         2      Teacher
2         1      Scientist



并根据主表中的ID,检索表格中标签上的几个字段....我想要做的是当我将表单的这些值存储在一个新表中时我只想存储id而不是在la中显示的文本值形式的贝尔。下面是我试过的代码。任何人都可以帮助我吗?




and based on the ID's present in the master table i retrieve few fields on a label in a form....What i want to do is when i store these values of the form in a new table i want only the id's to be stored and not the text values which are being displayed in the label of the form.Below is the code I tried..Can anyone help me?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
namespace Forms
{
    public partial class temporaryduty : System.Web.UI.Page
    {
        SqlConnection conn = new SqlConnection("Server; Database; Integrated security = true");
        protected void Page_Load(object sender, EventArgs e)
        {
            Lbltoday.Text = DateTime.Now.ToString();
            if (!IsPostBack)
            {
                GetName();
            }
        }
     private void GetName()
     {
         SqlCommand cmd = new SqlCommand("Select EMPID,Name FROM M_employee where IsActive=1 ORDER BY Name", conn);
         DataSet objDs = new DataSet();
         SqlDataAdapter sd = new SqlDataAdapter(cmd);
         conn.Open();
         sd.Fill(objDs);
         conn.Close();
         if (objDs.Tables[0].Rows.Count > 0)
         {
             ddlname.DataSource = objDs.Tables[0];
             ddlname.DataTextField = "Name";
             ddlname.DataValueField = "EMPID";
             ddlname.DataBind();
             ddlname.Items.Insert(0, "--Select--");
         }
     }
     protected void ddlname_SelectedIndexChanged(object sender, EventArgs e)
     {
         GetDivision(ddlname.SelectedItem.Value);
     }
     private void GetDivision(string Name)
     {
         SqlCommand cmd = new SqlCommand("SELECT M_employee.Name, M_Division.DIVISION, M_Division.DIVID AS Expr1, M_Designation.DesigID AS Expr2, M_Designation.Designation FROM M_employee INNER JOIN M_Division ON M_employee.DIVID = M_Division.DIVID INNER JOIN M_Designation ON M_employee.DesigID = M_Designation.DesigID WHERE M_employee.EMPID=@EMPID ", conn);
         cmd.Parameters.AddWithValue("@EMPID", Name);
         DataSet objDs = new DataSet();
         SqlDataAdapter sd = new SqlDataAdapter(cmd);
         conn.Open();
         sd.Fill(objDs);
         conn.Close();
         if (objDs.Tables[0].Rows.Count > 0)
         {
             lbldiv.Text = objDs.Tables[0].Rows[0]["DIVISION"].ToString();
             lbldesig.Text = objDs.Tables[0].Rows[0]["Designation"].ToString();
         }
     }
    protected void btnSubmit_Click2(object sender, EventArgs e)
    {
        string RelaseDate = Calendar1.SelectedDate.Date.ToString();
        SqlCommand cmd = new SqlCommand("Insert into T_TADA_tempform(EMPID,DIVID,DesigID) values(@EMPID,@DIVID,@DesigID)", conn);
        cmd.Parameters.AddWithValue("@EMPID", ddlname.SelectedValue);
        cmd.Parameters.AddWithValue("@DIVID", lbldesig.Text);
        cmd.Parameters.AddWithValue("@DesigID", lbldiv.Text);
        if (conn.State == ConnectionState.Closed)
        {
            conn.Open();
            int cnt = cmd.ExecuteNonQuery();
            conn.Close();
            if (cnt == 1)
            {
                Response.Redirect("form.aspx");
            }
            else
                Response.Write("Form has not been submitted,Please Try again!");
        }
    }
    }
    }

推荐答案

在btnSubmit_Click2方法,您将@DIVID和@DesigID参数设置为表单上标签的值。这些标签分别在GetDivision方法中设置分区的名称和名称的名称。



您需要在表单上将变量设置为DivID和DesigID的值,然后将这些变量用于参数。您可以在GetDivision方法中设置值。您可以使用更多标签,但这可能不太合乎需要。我建议将它们添加为隐藏变量。



祝你好运。



Greg
In the btnSubmit_Click2 method, you are setting the @DIVID and @DesigID parameters to be the values of the labels on the form. These labels are set the the name of the division and the name of the designation respectively in the GetDivision method.

You will need to set variables on the form to the value of the DivID and DesigID and then use those for the parameters. You can set the values in the GetDivision method. You can use more labels but this may not be visually desirable. I would suggest adding them as hidden variables.

Good luck.

Greg


这篇关于商店ID在数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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