Click here to Skip to main content
16,004,761 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi,

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

C#
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]Code block added - OriginalGriff[/edit]
Posted
Updated 21-Feb-12 23:51pm

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:
C#
string companyId = "AAA001";
string companyName = "Aardvark Enterprises";
if (companyName == companyId)
   {
   ...
   } 
And expecting it to match...
 
Share this answer
 
string str = "select comp_name from mCompnay JOIN temp ON ( mCompnay.comp_code = temp.CompCode ) WHERE comp_code='" + s + "'";


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.
 
Share this answer
 
v2
Comments
Tushar1999 22-Feb-12 6:12am    
may i call u... if u dont mind can u provide me ur phone number...
beevif 22-Feb-12 6:18am    
If you are not minding then you can ask your doubts through this site.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900