从索引 0 处开始,初始化字符串的格式不符合规范。代码如下:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;public partial class cx_Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {    }
    protected void Button1_Click(object sender, EventArgs e)
    {           
        SqlConnection con = new SqlConnection("local");
        con.Open();
        SqlCommand sql = new SqlCommand("select * from [sbcx] where [sbmc] [desc]");
        SqlDataAdapter admain = new SqlDataAdapter(sql);
                       DataSet ds=new DataSet();
        admain.Fill(ds,"table");
        GridView1.DataSource = ds.Tables["table"];
        GridView1.DataBind();
        con.Close();
        con.Dispose();
        
    }
}
 界面上定义了一个textbox控件一个button。我的意思是当在textbox输入任何设备名称时,点击button就可以查到关于这个设备在数据库里的所有记录。是不是代码有问题?在哪里??

解决方案 »

  1.   

    这个SQL是什么意思?想实现什么样的功能?我觉得你的意思可能是:
    SqlCommand sql = new SqlCommand("select * from [sbcx] order by [sbmc] desc");
      

  2.   

    大家有msn或uc的留下我细请教一下!谢谢了
      

  3.   

    SqlCommand sql = new SqlCommand("select * from [sbcx] order by [sbmc] desc");
    SQL语句有问题
      

  4.   

    string strsql = "select * from [sbcx] where [sbmc]='"+控件id.text.trim()+"' order by [sbmc] [desc]";
     SqlCommand sql = new SqlCommand(strsql);
      

  5.   

    select * from [sbcx] where [sbmc]='%"+textbox.text.trim()+"%' order by [sbmc] desc
    传入参数才可以查相关的数据啊
      

  6.   

    SqlConnection con = new SqlConnection("server=(local);uid=sa;pwd=sa;database=访问的数据库");
            con.Open();
           string strsql = "select * from [sbcx] where [sbmc]='"+控件id.text.trim()+"' order by [sbmc] [desc]";
            SqlDataAdapter admain = new SqlDataAdapter(sql);
                           DataSet ds=new DataSet();
            admain.Fill(ds,"table");
            GridView1.DataSource = ds.Tables["table"];
            GridView1.DataBind();
            con.Close();
            con.Dispose();
    //再试试