Click here to Skip to main content
15,299,443 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi All ,

I have a create grid view in asp.net using store prouder .

in store prouder I have customerID which is from another table how I can display name of customer instead of id number .

could any one help me please , I have tried a lot .

This my code

could any one help me please

Thanks

What I have tried:

<pre lang="c#"> private void BindGrid()
    {
        
        string constr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        using (SqlConnection con = new SqlConnection(constr))

        {
            using (SqlCommand cmd = new SqlCommand("usp_Counry"))

            {

               
                cmd.Parameters.AddWithValue("@Action", "SELECT");
             

                using (SqlDataAdapter sda = new SqlDataAdapter())
                {
                    cmd.CommandType = CommandType.StoredProcedure;
                    cmd.Connection = con;
                    sda.SelectCommand = cmd;
                    using (DataTable dt = new DataTable())
                    {
                        sda.Fill(dt);
                        GridView1.DataSource = dt;
                        GridView1.DataBind();
                        
                    }
                }
            }
        }


    }
Posted
Updated 2-Jan-21 21:34pm

1 solution

Unless your SP (which would appear to be very badly spelled, there is a "t" in "Country", and no "r" in "County") returns the customer name, you can't display it - unless you use a second query to use the ID to reference the name.

And we have no idea what your SP is doing so we really can't help you at all with that!
   
v2
Comments
coderom2019 3-Jan-21 4:02am
   
Sorry , you mean I make change in SP not in the c# code ?
OriginalGriff 3-Jan-21 4:22am
   
Probably, but remember: we can't see your screen, we can;t access your HDD, we can't read your mind!
So we have no idea at all what your SP is doing, or how it is doing it; no idea of your table structures; no access to your actual data!
coderom2019 3-Jan-21 6:08am
   
Thank you , I have solve it
OriginalGriff 3-Jan-21 6:21am
   
Excelent!

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