3层架构文本框 [英] 3 tier architecture textbox

查看:57
本文介绍了3层架构文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有3个文本框对应于我可以使用1按钮输入值的列,还有另一个用于搜索的按钮,当搜索textbox1并按下按钮时如果与数据列匹配则我希望它将所有其他值传递给相应的文本框我请专家帮帮我?提前致谢

注意:它的3层建筑



我尝试过:



DAL:

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:

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:

public DataTable Search()
{
    csDL dl = new csDL();
    return dl.SearchDB();
}

PL:

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();
}

推荐答案

为什么对3层的痴迷。这是n层,它不会使这样的愚蠢编码错误变得不可能:



您可能想要仔细查看Button2_Click处理程序中的代码。看到有什么问题:

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:
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();
}



首先,你创建一个 csBL 对象,不管它到底是什么。类,方法和变量名称都很重要!他们走自己的自我文档代码的方式很长。



接下来,你从三个TextBox中获取值,顺便说一下名为TextBox1,TextBox2和TextBox3(参见上文) ),然后对这些值不做任何事情。你只需抛弃这些值。



然后你调用搜索方法三次,转换它返回的任何内容一个字符串,然后存储上面三个变量中的任何值。然后你扔掉那些值,直到变量超出范围并且内容丢失为止,根本不与它们签约。



你似乎对n-痴迷层架构,但您不知道如何最简单地管理数据和调用方法。这对我来说似乎非常倒退。


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.


这篇关于3层架构文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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