我在界面上面拖了个文本框,按钮,GridView控件。想实现在文本框中输入数据库中的表名就显示相应表的信息,再换个表名就显示别一张表的信息。哪个大神知道的说下。不胜感激

解决方案 »

  1.   

    把查询的表明用textBox传到sql语句中去
    select * from table
    table用参数传进去
      

  2.   

    不知道这是不是你想要的结果。前台就是一文本框,一按钮,一数据控件。
      public void bind()
        {
            string sqlstr = "select * from " + TextBox1.Text.Trim();
            SqlConnection con = getCon();
            con.Open();
            SqlCommand cmd=new SqlCommand(sqlstr,con);
            SqlDataAdapter sda = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            sda.Fill(ds);
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
        public SqlConnection getCon()
        {
            string sqlcon = ConfigurationManager.AppSettings["constr"].ToString();
            SqlConnection con = new SqlConnection(sqlcon);
            return con;
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            bind();
        }
      

  3.   

    Gridview.datasource=sqlhelper.getDataSet("select * from syscolumns where id in (select id from sysobjects where name='"+TextBox.Text+"')");
    Gridview.databind();
      

  4.   

    string sql="select * from {0}"
    sql=string.Format(sql,textBox.text);
    这样就ok了
      

  5.   

    采用textbox的onblur事件 onblur="js中的某个方法" 该方法在调用后台的代码
    就是通过js来调用后台方法,这个方法实现的是gridview的重行绑定
      

  6.   

    我觉得LZ要求的是不需要按钮的 输入完直接触发的 onblur时间就是就可以js方法中先检查输入框是否为空 如果是空就不调用后台了
      

  7.   

    4楼可以实现
    但是要考虑异常,如输入的表名在DB中不存在
    在bind()方法中加入try catch 
      

  8.   

    string sqlcon = ConfigurationManager.AppSettings["constr"].ToString();
    这句出现未将对象引用设置到对象实例
    是怎么回事啊