可能是forecolor的问题
你用鼠标选一下datagrid在页面的大概位置
看能不能看到数据,如果能的话,调个颜色就行
我遇到过这个情况,不知道你的和我的是否相同

解决方案 »

  1.   

    using System;
    using System.Collections;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.SessionState;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.HtmlControls;namespace test
    {
    /// <summary>
    /// WebForm1 的摘要说明。
    /// </summary>
    public class WebForm1 : System.Web.UI.Page
    {
    protected System.Data.SqlClient.SqlConnection sqlConnection1;
    protected System.Data.SqlClient.SqlDataAdapter sqlDataAdapter1;
    protected System.Data.SqlClient.SqlCommand sqlSelectCommand1;
    protected System.Data.SqlClient.SqlCommand sqlInsertCommand1;
    protected System.Data.SqlClient.SqlCommand sqlUpdateCommand1;
    protected System.Web.UI.WebControls.DataGrid DataGrid1;
    protected test.DataSet1 dataSet11;
    protected System.Data.SqlClient.SqlCommand sqlDeleteCommand1;

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    } #region Web Form Designer generated code
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN:该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.sqlConnection1 = new System.Data.SqlClient.SqlConnection();
    this.sqlDataAdapter1 = new System.Data.SqlClient.SqlDataAdapter();
    this.sqlSelectCommand1 = new System.Data.SqlClient.SqlCommand();
    this.sqlInsertCommand1 = new System.Data.SqlClient.SqlCommand();
    this.sqlUpdateCommand1 = new System.Data.SqlClient.SqlCommand();
    this.sqlDeleteCommand1 = new System.Data.SqlClient.SqlCommand();
    this.dataSet11 = new test.DataSet1();
    ((System.ComponentModel.ISupportInitialize)(this.dataSet11)).BeginInit();
    // 
    // sqlConnection1
    // 
    this.sqlConnection1.ConnectionString = "data source=192.168.0.1;initial catalog=lucheng;persist security info=False;use" +
    "r id=lucheng;workstation id=ZHANGCHENGJUN;packet size=4096";
    // 
    // sqlDataAdapter1
    // 
    this.sqlDataAdapter1.DeleteCommand = this.sqlDeleteCommand1;
    this.sqlDataAdapter1.InsertCommand = this.sqlInsertCommand1;
    this.sqlDataAdapter1.SelectCommand = this.sqlSelectCommand1;
    this.sqlDataAdapter1.TableMappings.AddRange(new System.Data.Common.DataTableMapping[] {
      new System.Data.Common.DataTableMapping("Table", "information", new System.Data.Common.DataColumnMapping[] {
     new System.Data.Common.DataColumnMapping("id", "id"),
     new System.Data.Common.DataColumnMapping("content", "content")})});
    this.sqlDataAdapter1.UpdateCommand = this.sqlUpdateCommand1;
    // 
    // sqlSelectCommand1
    // 
    this.sqlSelectCommand1.CommandText = "SELECT id, content FROM information";
    this.sqlSelectCommand1.Connection = this.sqlConnection1;
    // 
    // sqlInsertCommand1
    // 
    this.sqlInsertCommand1.CommandText = "INSERT INTO information(content) VALUES (@content); SELECT id, content FROM infor" +
    "mation WHERE (id = @@IDENTITY)";
    this.sqlInsertCommand1.Connection = this.sqlConnection1;
    this.sqlInsertCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@content", System.Data.SqlDbType.VarChar, 50, "content"));
    // 
    // sqlUpdateCommand1
    // 
    this.sqlUpdateCommand1.CommandText = "UPDATE information SET content = @content WHERE (id = @Original_id) AND (content " +
    "= @Original_content OR @Original_content IS NULL AND content IS NULL); SELECT id" +
    ", content FROM information WHERE (id = @id)";
    this.sqlUpdateCommand1.Connection = this.sqlConnection1;
    this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@content", System.Data.SqlDbType.VarChar, 50, "content"));
    this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_id", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "id", System.Data.DataRowVersion.Original, null));
    this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_content", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "content", System.Data.DataRowVersion.Original, null));
    this.sqlUpdateCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@id", System.Data.SqlDbType.Int, 4, "id"));
    // 
    // sqlDeleteCommand1
    // 
    this.sqlDeleteCommand1.CommandText = "DELETE FROM information WHERE (id = @Original_id) AND (content = @Original_conten" +
    "t OR @Original_content IS NULL AND content IS NULL)";
    this.sqlDeleteCommand1.Connection = this.sqlConnection1;
    this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_id", System.Data.SqlDbType.Int, 4, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "id", System.Data.DataRowVersion.Original, null));
    this.sqlDeleteCommand1.Parameters.Add(new System.Data.SqlClient.SqlParameter("@Original_content", System.Data.SqlDbType.VarChar, 50, System.Data.ParameterDirection.Input, false, ((System.Byte)(0)), ((System.Byte)(0)), "content", System.Data.DataRowVersion.Original, null));
    // 
    // dataSet11
    // 
    this.dataSet11.DataSetName = "DataSet1";
    this.dataSet11.Locale = new System.Globalization.CultureInfo("zh-CN");
    this.dataSet11.Namespace = "http://www.tempuri.org/DataSet1.xsd";
    this.Load += new System.EventHandler(this.Page_Load);
    ((System.ComponentModel.ISupportInitialize)(this.dataSet11)).EndInit(); }
    #endregion
    }
    }
      

  2.   

    <%@ Page language="c#" Codebehind="WebForm1.aspx.cs" AutoEventWireup="false" Inherits="test.WebForm1" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
    <HTML>
    <HEAD>
    <title>WebForm1</title>
    <meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
    <meta name="CODE_LANGUAGE" Content="C#">
    <meta name="vs_defaultClientScript" content="JavaScript">
    <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
    </HEAD>
    <body MS_POSITIONING="GridLayout">
    <form id="Form1" method="post" runat="server">
    <FONT face="宋体">
    <asp:DataGrid id=DataGrid1 style="Z-INDEX: 101; LEFT: 273px; POSITION: absolute; TOP: 112px" runat="server" DataSource="<%# dataSet11 %>">
    </asp:DataGrid></FONT>
    </form>
    </body>
    </HTML>
      

  3.   

    呵呵!初学?
    先1\open connection;
    2\new sqlDataAdapter;
    3\new DataSet;
    4\ Fill;
    5\bind;
    SqlConnection  myConnection= new SqlConnection(str);
    string cmd = "select * from student where name='dh'";
    SqlDataAdapter myCommand = new SqlDataAdapter(cmd,myConnection);
    DataSet ds=new DataSet();
    myCommand.Fill(ds," ");
    DG1.DataSource = ds.Tables["num"].DefaultView;
    DG1.DataBind();
      

  4.   

    TO:dhdhdh(hui)
    这个我知道,我也不是ASP.net初学者,但是是vs.net的初学者,我过去一直用记事本写程序,但现在为了提高效率就用vs.net了
    我是拖放一个SQLconnection,sqldataadapter,dataset,并设置参数
    再拖放一个datagrid,设置数据源
    但结果就无法显示