你的数据库连接是否有问题
server=localhost;integrated security=true;user id=sa;database=pubs;password=
这句有点不顺眼

解决方案 »

  1.   

    SqlConnection con = new SqlConnection( "data source=localhost;initial catalog=pubs;persist security info=False;user id=sa;workstation id=localhost;packet size=4096");
    我已经改成这样
      

  2.   

    try
    {
    con.Open();
    dgAuthors.DataSource = cmd.ExecuteReader();
    dgAuthors.DataBind();
    con.Close();
    }
    catch( Exception ) {}catch(Exception){}
    catch里面的异常类型,怎么没有定义?
    这样:catch(Exception ee){}
      

  3.   

    把AutoGenerateColumns="False"改成AutoGenerateColumns="True"
      

  4.   

    DataSet dsSource=……;
    dgAuthor.SetDataBinding(dsSource.Tables[0],"");
      

  5.   

    to fq_ln,程序运行没有任何结果,整个页面为空
     to others: 这些我都试过了,还是一样
      

  6.   

    private void BindData()
    {
      SqlConnection con = new SqlConnection( "server=localhost;integrated security=true;user id=sa;database=pubs;password=");
      SqlCommand cmd = new SqlCommand( "SELECT * FROM authors", con );
      try
       {
    con.Open();
             SqlDataReader mread  = cmd.ExecuteReade(CommandBehavior.CloseConnection);
    dgAuthors.DataSource = mread;
    dgAuthors.DataBind();
    con.Close();
        }
      catch( Exception ) 
      {}
      if( con != null && con.State == ConnectionState.Open )
    con.Close();
    }
      

  7.   

    你这样试看!
    string sql="server=localhost;uid=sa;database=pubs;password=";
    SqlConnection con = new SqlConnection(sql);
    SqlCommand cmd = new SqlCommand( "SELECT * FROM authors", con );
    SqlDataAdapt da=new SqlDataAdapt(cmd);
    DataSet ds=new DataSet();
    da.Fill(ds);
    try
    {
       con.Open();
       dgAuthors.DataSource = ds.Tables[0].DefaultView;
       dgAuthors.DataBind();
    }
    catch( Exception ) {}
    ds.disposed();
    myComm.Dispose();
    cmd.Dispose();
    da.Dispose();
    conn.close();
      

  8.   

    (1)把AutoGenerateColumns="False"改成AutoGenerateColumns="True"
    (2)BindData方法改一下
    SqlConnection  myConnection = new SqlConnection("user id=sa;password=123;initial catalog=pubs;data source=echo");
    myConnection.Open();   
    SqlCommand myCommand = new SqlCommand("select * from Authors", myConnection);
    SqlDataReader dr = myCommand.ExecuteReader();
    dgAuthors.DataSource=dr;
    dgAuthors.DataBind();
    myConnection.Close();
      

  9.   

    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient" %> 
    <script language="C#" runat="server">
        protected void Page_Load(Object sender, EventArgs e) {
            SqlConnection myConnection = new SqlConnection("server=localhost;database=pubs;uid=sa;pwd=");
            SqlCommand myCommand = new SqlCommand("select * from Authors", myConnection);        myConnection.Open();        SqlDataReader dr = myCommand.ExecuteReader();        MyDataGrid.DataSource = dr;
            MyDataGrid.DataBind();        myConnection.Close();
        }</script><html>
    <body>  <h3><font face="&Euml;&Icirc;&Igrave;&aring;">DataGrid &iquest;&Oslash;&frac14;&thorn;&micro;&Auml;&frac14;ò&micro;&yen;&Ntilde;&iexcl;&Ocirc;&ntilde;</font></h3>  <ASP:DataGrid id="MyDataGrid" runat="server"
        Width="700"
        BackColor="#ccccff"
        BorderColor="black"
        ShowFooter="false"
        CellPadding=3
        CellSpacing="0"
        Font-Name="&Euml;&Icirc;&Igrave;&aring;"
        Font-Size="8pt"
        HeaderStyle-BackColor="#aaaadd"
        EnableViewState="false"
      /></body>
    </html>
      

  10.   

    <%@ Page language="c#" Codebehind="datagrid.aspx.cs" AutoEventWireup="false"%>
    改为:
    <%@ Page language="c#" %>