Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
140
Dynamic binding with dataset
posted

Hi there,

After long time searching by myself with no result, I finally decide to ask for your help. So this is my problem :

I've got a XamDataGrid and a Combobox. For now the XamDataGrid is bind to a Dataset and his TableAdapter ( created with the DataSource Window). The XamDataGrind display the result of a storage procedure. The Combobox is binded to a simple table containing all the storage procedures i will need to fill the XamDatagrid ( the user can dynamically create a new procedure ). I would like to bind the ComboBox SelectedValue to the XamDataGrid source, and so the XamDataGrid could display all my StorageProc Result depend of the Combobox value.

I don't know if i'm clear.. I hope you could help me with that.

Thanks, Luc.

PS: Excuse my English please it's not my native language.

Parents
No Data
Reply
  • 140
    Verified Answer
    posted

    I finally found a solution by myself ! Here this is what I did :

    private void CB_SelectionChanged(object sender, SelectionChangedEventArgs e)
    {
        string storageProcString = ComboProc.SelectedValue.ToString();
        GetData(storageProcString);

    }
    private void GetData(string procName)
    {
        dgServiceRequests.DataSource = null;  //xamdatagrid.datasource = null is my way to refresh the xamdatagrid 
        DataSet gridSet = new DataSet();
        dgServiceRequests.DataSource = bindingSource;
        using (SdaConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlData"].ConnectionString))
        {
            SqlDataAdapter adapter = new SqlDataAdapter(procName, SdaConnection);
            SdaConnection.Open();
            adapter.SelectCommand.CommandType = CommandType.StoredProcedure;
            adapter.Fill(gridSet, "resulttable");
            bindingSource.DataSource = gridSet;
        }
    }

Children
No Data