Click here to Skip to main content
15,887,083 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I hve 3 textbox corresponding to the column where i can enter value using 1 button and also another button for searching,when searching textbox1 and press buttton if match with data column then i want it to pass all the other value to respective textbox.I kindly request expert to help me?? Thanks in advance
NOTE:its a 3 Tier Architecture

What I have tried:

DAL:
C#
public DataTable SearchDB()
{
    string name="";
    string age="";
    string address="";

    SqlCommand cmd = new SqlCommand("PSearch", con);
    cmd.CommandType = CommandType.StoredProcedure;
    cmd.Parameters.Add("@name", SqlDbType.VarChar, 50);
    cmd.Parameters["@name"].Value = name;
    /* cmd.Parameters.Add("@age", SqlDbType.VarChar, 50);
     cmd.Parameters["@age"].Value = age;
     cmd.Parameters.Add("@address", SqlDbType.VarChar, 50);
     cmd.Parameters["@address"].Value = address;*/
    DataTable dt = new DataTable();
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    da.Fill(dt);
    if (dt.Rows.Count > 0)
    {
        name = dt.Rows[0][1].ToString();
        age = dt.Rows[0][2].ToString();
        address = dt.Rows[0][3].ToString();
    }
	return dt;
}
BAL:
C#
public DataTable Search()
{
    csDL dl = new csDL();
    return dl.SearchDB();
}
PL:
C#
protected void Button2_Click(object sender, EventArgs e)
{
    csBL bl=new csBL();
    string name = TextBox1.Text;
    string age = TextBox2.Text;
    string address = TextBox3.Text;

    name = bl.Search().ToString() ;
    age = bl.Search().ToString();
    address = bl.Search().ToString();
}
Posted
Updated 2-Mar-17 14:08pm
v2
Comments
[no name] 2-Mar-17 17:36pm    
Help... with.... what?
Garth J Lancaster 2-Mar-17 19:15pm    
It's really hard on a forum such as this to ask questions that may have 'graphical' content - what I'd suggest is you do a 'mock up' of the text boxes on a WinForm or such, take a screen shot of that, annotate the screen shot if required showing what goes where/flow, post the screen shot to imgur and then put the imgur link back with your question, so people can 'see' what you're trying to accomplish - dont forget, we cant see your screen/mind,so it gets hard for us to help you
Karthik_Mahalingam 2-Mar-17 22:18pm    
you will have to pass the parameters.

1 solution

Why the obsession with "3 tier". It's n-tier and it doesn't make stupid coding mistakes like this impossible:

You might want to take a closer look at the code in your Button2_Click handler. See anything wrong with this:
C#
protected void Button2_Click(object sender, EventArgs e)
{
    csBL bl=new csBL();
    string name = TextBox1.Text;
    string age = TextBox2.Text;
    string address = TextBox3.Text;

    name = bl.Search().ToString() ;
    age = bl.Search().ToString();
    address = bl.Search().ToString();
}

First, you create a csBL object, whatever the hell that is. CLASS, METHOD, AND VARIABLE NAMES ARE IMPORTANT! THEY GO A LONG WAY TOWARDS SELF DOCUMENTING CODE.

Next, you grab the values from three TextBox's, terribly named TextBox1, TextBox2 and TextBox3, by the way (see above), and then do nothing with those values. You simply throw those values away.

You then call a Search method three times, converting whatever it returns to a string and then storing whatever value that is in your three variables from above. You then throw those values away, doing nothign with them at all until the variables go out of scope and the content is lost.

You seem to be obsessed with n-tier architecture but you don't know the first thing about how to do the simplest management of your data and call methods. That seems very backwards to me.
 
Share this answer
 
v2
Comments
Graeme_Grant 2-Mar-17 21:37pm    
c sharp Business layer???

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