Search code examples
c#.netdatasetruntimestrongly-typed-dataset

Edit Dataset's CommandText


How can I edit Dataset's (.xsd file) Query's CommandText in Runtime mode ?

How can give new sql query ?


Solution

  • It is not the Dataset that contains the CommandText, it is the DataAdapter which contains 4 commands :

    public sealed class SqlDataAdapter
    {
        public SqlCommand DeleteCommand { get; set; }
        public SqlCommand InsertCommand { get; set; }
        public SqlCommand SelectCommand { get; set; }
        public SqlCommand UpdateCommand { get; set; }
    }
    

    For example, if you want to change the select sql :

    var dataset = new MyDataSet();
    var adapter = new MyTableAdapter();
    adapter.Adapter.SelectCommand.CommandText = "SELECT * FROM FOO";
    adapter.Fill(dataset.MyTable);