RT

解决方案 »

  1.   

    这个太简单了,写个方法就ok了
    public void Bind()
    {
        SqlConnection con = new SqlConnection("连接字符串");
        con.open();
        SqlDataAdapter da = new SqlDataAdapter("select * from table",con);
        DataSet ds = new DataSet();
        da.fill(ds,"table");
        DataGrid1.DataSource = ds.Tables["table"];
        DataGrid1.DataBind();
    }
    然后再Page_Load()或者其他的事件中去调用就OK了
    然后就结贴了
      

  2.   

    WINFORM里也差不多,不要DATABIND就可以了
      

  3.   

    我说的是在WinForm 里怎么绑定啊?是不是WinForm里必须先DataSet然后在绑定DataGrid?,如果直接绑定comm.ExcuteQuery 就不行???
      

  4.   

    在WinForm 中 我这样绑定 为什么有错???private void button1_Click(object sender, System.EventArgs e)
    {
    string strConn = "Provider=Microsoft.Jet.OleDb.4.0;data source=" + System.Configuration.ConfigurationSettings.AppSettings["Path"];
    string strSQL = "select * from user";

    OleDbConnection conn = new OleDbConnection(strConn);
    conn.Open(); OleDbCommand comm = new OleDbCommand(strSQL,conn);
    dg.DataSource = comm.ExecuteReader();
    conn.Close();
    }
      

  5.   

    .........//连接数据库            
    string strSql = "SELECT * FROM [tablename]";
                OleDbDataAdapter da = new OleDbDataAdapter(strSql, mc );
                DataSet ds = new DataSet( );
                 dg.DataSource = ds.Tables["tablename"];
      

  6.   

    如果是WEBFORM的话:MyDataGrid(datagrid的名称)
    DataSet ds=new DataSet();
    SqlDataAdapter adapter  =new SqlDataAdapter(“sql语句”, myConnection);
    adapter.Fill(ds, "数据库表名");
    MyDataGrid.DataSource = ds.Tables["数据库表名"].DefaultView;
    MyDataGrid.DataBind();如果是WINFORM的话:
    MyDataGrid.DataSource = ds.Tables["数据库表名"];(一句就够了)
      

  7.   

    string idSql ="select * from user";
    private DataSet ExecuteDataSet(
                string commandText)
            {
                return ExecuteDataSet(commandText, CommandType.Text, (SqlParameter[])null);
            }
     DataTable idDt =ExecuteDataSet(idSql).Tables[0];
    dg.DataSoure = idDt;
    嘿嘿,我就爱回答你的问题,分少点也没关系.
      

  8.   

    绑定成功了,绑定后的特难看,现在的问题是都有那些属性可以用来美化 DataGrid ?
      

  9.   

    把ExecuteDataSet重载下,把参数初始化了就可以了.