当我使用Developer Express 的GridControl控件时,使用下面代码,一切都很好用,但是当我像使用
SqldataAdapter.Update(dataSetName,tableName)更新数据库时 却没有反映;而相同的代码放到微软的DataGrid控件中时却没有毛病。情高手指点啊!谢谢! private void InitData()
{
string sqlString ="SELECT MB, Description AS 描述 FROM MB";
SqlConnection sqlConnection = new SqlConnection(Global.connectonString);
sqlDataAdapter = new SqlDataAdapter(sqlString,sqlConnection);
sqlCommandBuilder = new SqlCommandBuilder(sqlDataAdapter); sqlConnection.Open();
dataSet_MB = new DataSet();
sqlDataAdapter.Fill(dataSet_MB,"MB");
gridControl1.DataSource = dataSet_MB.Tables["MB"];
sqlConnection.Close();
}

解决方案 »

  1.   

    用过Developer Express Inc.NET 控件的朋友,请告诉一声啊
      

  2.   

    this.gridXXX.DataSource = dataSet_MB.Tables[0].DefaultView;
      

  3.   

    to timiil(小华) :谢谢,不过也不行啊!
      

  4.   

    从控件的帮助文件来看,用法和DataGrid一样,应该是继承那种吧,对DataGrid好用的对第三方控件的DataGrid是不是也应该好用?下面是它的帮助文件:
    XtraGridPosting Data to a Connected Database
      [CSHARP]
    Language 
    ○ C#
    ○ Visual Basic
    ○ Show All
    The .Net data model implies that a control bound to a database using DbDataAdapter and DataTable objects does not immediately post changes after they have been made. Instead, changes are accumulated in the DataTable and you have to manually call a specific method to update the database. The XtraGrid behaves in a similar way: changes you made while editing data (adding, deleting or modifying records) are saved in a corresponding DataTable. To post these changes to the database, you should call the data adapter's System.Data.Common.DbDataAdapter.Update method. 
    Before calling this method, make sure that the grid control has saved all the changes made to the currently focused row (the end-user could enter new data but forget to update the row). For this purpose, you should call the BaseView.CloseEditor and ColumnView.UpdateCurrentRow methods. 
    The following code lists the UpdateDatasource method which posts the changes stored in the custom Suppliers and Products DataTables to a database. It is assumed that the data adapters (oleDbDataAdapter1 and oleDbDataAdapter2) contain appropriate Update SQL statements to modify the corresponding tables in the database. By default, these statements are created by the adapter's Wizards. 
    The dataSet11 object represents a DataSet instance and this provides access to our tables. 
      

  5.   

    我也用DataAdapter向导做了,都是一个效果,对这个控件都不好用。不应该是控件的问题吧,很简单啊 ,是不是那个属性没设置好,用过的朋友告诉我一声啊!
      

  6.   

    我以前也遇到这样的问题,为了对DataTable和SQLSERVER数据库表同时进行保存操作
    我用了事务处理,目的是为了能在出错时回滚,想简单使用sqlCommandBuilder生成命令
    结果出错,后来我用SqlDataAdapter向导生成就行了(当然得有主键保证各命令成功生成),
    不想用向导生成数据集,最后只好自己手动写各命令的Command,CommandText你可以先用向导生成,然后复制一下就行了,我有回答对你一定有
      

  7.   

    这是在这个控件的官方网站上找到的答案,用这个控件的朋友相互联系啊qq15825508;真的很好的控件!
    #region  update
    public void UpdateDatasource(GridControl grid) 
    {
    //Save the latest changes to the bound DataTable
    ColumnView view = (ColumnView)grid.DefaultView;
    view.CloseEditor();
    if(!view.UpdateCurrentRow()) return; //Update the database's Suppliers table to which oleDBDataAdapter1 is connected
    DoUpdate(oleDbDataAdapter1, dataSet_Item1.Tables["Item"]);
    } public void DoUpdate(DbDataAdapter dataAdapter, System.Data.DataTable dataTable) 
    {
    try 
    {
    dataAdapter.Update(dataTable);

    catch(Exception ex) 
    {
    MessageBox.Show(ex.Message);
    }
    }
    #endregion
      

  8.   

    如果只是SqlDataAdapter.update,那不会是控件本身的问题,我用就行好,我只是在用到“事务处理"时出现了点小问题。
    我有一次也出了问题,那是因为自己不小心,那Dataset不在同一个类中
    如果你用向导生成SqlDataAdapter和DataSet一定没问题