using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;namespace 进销存管理系统
{
    public partial class WareDataManage :System.Windows.Forms.Form 
    {
        private bool blSellTableShow;
        private DataSet ds = new DataSet();
        private LinkDataBase link = new LinkDataBase();
        private string tempTableName = "商品清单";
        private string tempStrSQL = "SELECT 货号, 条码, 拼音编码, 品名, 单位, 进货价, 销售价1, 销售价2, 规格, 产地, 类别, 最低售价 FROM 商品清单";        public WareDataManage()
        {
            InitializeComponent();
        }        public WareDataManage(bool blShowToolBar)
        {
            InitializeComponent();            this.ds = link.SelectDataBase(tempStrSQL, tempTableName);
            //this.DataGridStateControl(blShowToolBar);
            this.dgrd_WareData.DataSource = ds.Tables[0];
            this.toolStrip1.Enabled = blShowToolBar;
        }
        /*
        private void DataGridStateControl(bool blReadOnly)
        {
            DataGridTableStyle ts = new DataGridTableStyle();
            ts.AlternatingBackColor = Color.LightGray;
            ts.MappingName = this.ds.Tables[0].TableName;
            ts.AllowSorting = false;            int numCols = this.ds.Tables[0].Columns.Count;
            for (int i = 0; i < numCols; i++)
            {
                if (blReadOnly == true)
                {
                    if (i == 4)
                    {
                        DataTable tempTable = new DataTable();
                        tempTable.Columns.Add();
                        object[] rowValues = new object[] { "包", "瓶", "盒", "带", "箱" };
                        for (int j = 0; j < 5; j++)
                        {
                            tempTable.Rows.Add(tempTable.NewRow());
                            tempTable.Rows[j][0] = rowValues[j];
                        }
                        DataGridComboBoxColumn aColumnTextColumn = new DataGridComboBoxColumn(tempTable,0,0);
                        aColumnTextColumn.MappingName = this.ds.Tables[0].Columns[i].ColumnName;
                        aColumnTextColumn.HeaderText = this.ds.Tables[0].Columns[i].ColumnName;
                        aColumnTextColumn.NullText = "";
                        ts.GridColumnStyles.Add(aColumnTextColumn);
                    }
                    else
                    {
                        DataGridTextBoxColumn aColumnTextColumn = new DataGridTextBoxColumn();
                        aColumnTextColumn.MappingName = this.ds.Tables[0].Columns[i].ColumnName;
                        aColumnTextColumn.HeaderText = this.ds.Tables[0].Columns[i].ColumnName;
                        aColumnTextColumn.NullText = "";
                        aColumnTextColumn.Format = "F";
                        ts.GridColumnStyles.Add(aColumnTextColumn);
                    }
                }
                else
                {
                    DataGridNoActiveCellColumn aColumnTextColumn = new DataGridNoActiveCellColumn();
                    aColumnTextColumn.MappingName = this.ds.Tables[0].Columns[i].ColumnName;
                    aColumnTextColumn.HeaderText = this.ds.Tables[0].Columns[i].ColumnName;
                    aColumnTextColumn.NullText = "";
                    aColumnTextColumn.Format = "F";
                    ts.GridColumnStyles.Add(aColumnTextColumn);
                }
            }
            //this.dgrd_WareData..Add(ts);
        }
         */ 
    }
}
连接数据库代码
using System;
using System.Data;
using System.Data.SqlClient;namespace 进销存管理系统
{
/// <summary>
/// LinkDataBase 的摘要说明。
/// </summary>
public class LinkDataBase
{
private string strSQL;
        private string connectionString = "workstation id=.;Integrated Security=SSPI;database=jxcbook";
private SqlConnection myConnection;
private SqlCommandBuilder sqlCmdBld;
private DataSet ds=new DataSet();
private SqlDataAdapter da; public LinkDataBase()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
        public DataSet SelectDataBase(string tempStrSQL, string tempTableName)
        {
            this.strSQL = tempStrSQL;
            this.myConnection = new SqlConnection(this.connectionString);
            this.da = new SqlDataAdapter(this.strSQL, this.myConnection);
            this.ds.Clear();
            this.da.Fill(ds, tempTableName);
            return ds;
        }
        public DataSet UpdateDataBase(DataSet changedDataSet, string tableName)
        {
            this.myConnection = new SqlConnection(this.connectionString);
            this.da = new SqlDataAdapter(this.strSQL, this.myConnection);
            this.sqlCmdBld = new SqlCommandBuilder(da);
            this.da.Update(changedDataSet, tableName);
            return changedDataSet;
        } //
        public DataTable SelectDataBase(string tempStrSQL)
        {
            this.myConnection = new SqlConnection(this.connectionString);
            DataSet tempDataSet = new DataSet();
            this.da = new SqlDataAdapter(tempStrSQL, this.myConnection);
            this.da.Fill(tempDataSet);
            return tempDataSet.Tables[0];
        }
        public int UpdateDataBase(string tempStrSQL)
        {
            this.myConnection = new SqlConnection(this.connectionString);
            this.myConnection.Open();
            SqlCommand tempSqlCommand = new SqlCommand(tempStrSQL, this.myConnection);
            int intNumber = tempSqlCommand.ExecuteNonQuery();
            myConnection.Close();
            return intNumber;
        }
}
}

解决方案 »

  1.   

    在下面这一句设置个断点,看看表中是否确实有数据:     this.dgrd_WareData.DataSource = ds.Tables[0]; 
      

  2.   

             public WareDataManage() 
            { 
                InitializeComponent(); 
                this.ds = link.SelectDataBase(tempStrSQL, tempTableName); 
                //this.DataGridStateControl(blShowToolBar); 
                this.dgrd_WareData.DataSource = ds.Tables[0]; 
            }        
    这么写试试
      

  3.   

     this.dgrd_WareData.DataSource = ds.Tables[0]; 
    后面不是还有一句吗
    this.dgrd_WareData.DataBind();
    好像都没看到。。
      

  4.   

    根本就没有databind()那个方法!!