zoukankan      html  css  js  c++  java
  • 【ASP.NET】传值问题及读取数据库内容——补充

    net小伙在ASP】传值问题及读取数据库内容中已经介绍过ASP的页面传值的问题。但是net小伙发现此文的代码只适合单个GridView控件的页面传值,如果一个主页面当中有两个以上的GridView控件,此代码就不会起作用了。在net小伙纠结了很长的时间之后,并请教了高手,这个问题就被搞定了。

    其实解决的方法很简单,现在感觉到代码真的很神奇,一句代码就可以实现很多东西。问题的解决方案就是修改数据库的查询命令,使用联合查询的方式从若干个表中查询内容。修改后的代码如下:

    protected void Page_Load(object sender, EventArgs e)

    {

    this.Title = "新闻显示!";

    this.TextBox1.Text = Request["title"].ToString();

    string a = Request["title"].ToString();

    //Response.Write(a);

    SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings

    ["username"].ConnectionString);

    con.Open();

    SqlCommand com = new SqlCommand("select * from Tsinghuanews where title='" + a + "'

    union select * from latestnews where title='" + a + "'

    union select * from activities where title='" + a + "' ", con);
    SqlDataReader dr = com.ExecuteReader();
    if (dr.Read())
         this.TextBox2.Text = dr["cotent"].ToString();
          TextBox2.DataBind();
    }

    con.Close();



    }



     

  • 相关阅读:
    CentOS 7.3 CDH 5.10.0 Druid0.12.4安装记录
    cloudera manager卸载流程
    CDH5.10.0 离线安装(共3节点) 转
    CentOS 7 安装Httpd(转)
    CentOS下MySQL的彻底卸载
    CentOS7 修改主机名
    sendEvent()
    QSignalMapper Class
    ubuntu12.04开启虚拟机的unity模式
    BCM_I2C函数更改
  • 原文地址:https://www.cnblogs.com/ngnetboy/p/2390112.html
Copyright © 2011-2022 走看看