我想在"label.text"中获取公司名称 [英] i want to get the company name in the "label.text"

查看:81
本文介绍了我想在"label.text"中获取公司名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我正在开发一个网页,我要从两个表"mCompany"和"temp"中检索所有数据.

当我从登录页面登录时,它向我证明了员工的"User_ID".
成功登录后,我会到达我正在使用的页面...

现在...我想要什么...

我想要"mCompany"表中的 comany名称,其中(temp.Compny_code = mCompany.Compny_code)...

我想使用JOIN和DATASET以及SQLDATAADAPTER .....
这是我正在使用的代码.......但是它进入了if条件的"else"部分",我不知道为什么...

请提供代码帮助



i m developing a web page i which all the data is being retrived from two tables "mCompany" and "temp".

when i login from the login page it provedes me the "User_ID" of the employee.
after successful login i reach to the page on which i m working...

now.... what i want...

i want the comany name from "mCompany" table where (temp.Compny_code = mCompany.Compny_code)...

i want to do it using JOIN and DATASET and SQLDATAADAPTER.....
here is my code which i m using....... but it is going into the "else" part of if condition" i dont no why...

please help with the code

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.Timers;
using System.Data.SqlClient;
using System.Data;
using System.Text;
using System.Drawing;

public partial class COMPLIANCE_CALENDAR : System.Web.UI.Page
{
    SqlConnection cn = new SqlConnection("server='fre-ggn-fstest\\sharepoint'; database = 'DMS1'; integrated security = 'true';");
    SqlDataAdapter sda;
    DataSet ds;

    
    string s;
    int i;

    protected void Page_Load(object sender, EventArgs e)
    {
        cn.Open();

        LblDateto.Text = DateTime.Now.ToString();
        LblDatetill.Text = DateTime.Now.AddDays(2).ToString();
        s = Session["sessFirstName"].ToString();                  // here i m getting the user id from login page

        getCompName();   // here i m calling the function that will give me the company name in the label

        //LblCompName.Text = s;
    }

    public void getCompName()
    {
        string str = "select comp_name from mCompnay JOIN temp ON ( mCompnay.comp_code = temp.CompCode ) WHERE comp_code='" + s + "'";

        sda = new SqlDataAdapter(str, cn);
        ds = new DataSet();
        sda.Fill(ds);

        for (i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
        {
            if (ds.Tables[0].Rows[i].ItemArray[i].ToString() == s.ToString())
            {
                LblCompName.Text = ds.Tables[0].Rows[i].ItemArray[i + 1].ToString();
            }
            else
            {
                LblCompName.Text = "can not display company name";
            }
        }

       // LblCompName.Text= ds.Tables["mCompnay"].Columns["comp_name"].ToString();
    }

}



[edit]已添加代码块-OriginalGriff [/edit]



[edit]Code block added - OriginalGriff[/edit]

推荐答案

您为什么还要其他?
忽略不必要的ToString(不必将字符串转换为字符串,它们已经...),您正在将从一个表中检索的值与用于检索它的另一个值进行比较.
与您正在执行的操作相同的代码是:
Why would you expect anything else?
Ignoring the unnecessary ToStrings (you don''t have to convert strings to strings, they are already...), you are comparing a value retrieved from one table against a different value which was used to retrieve it.
The equivalent code to what you are doing is:
string companyId = "AAA001";
string companyName = "Aardvark Enterprises";
if (companyName == companyId)
   {
   ...
   } 

并期望它匹配...


string str = "select comp_name from mCompnay JOIN temp ON ( mCompnay.comp_code = temp.CompCode ) WHERE comp_code=''" + s + "''";



这将给出公司名称.

s.ToString()将给出名字(我想是登录名)

我认为这两个价值观并不相同.如果我的猜测是正确的,它将仅进入其他部分.请更改if条件/更改选择查询(在查询中包括用户名).请澄清任何疑问.



this will give the company name..

s.ToString()will give the firstname( i guess the loggedin name)

I think both the values are not same. If my guess is correct it will go to else part only. kindly change the if condition/change the select query(include the username in the query). any doubts pls clarify.


这篇关于我想在"label.text"中获取公司名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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