Data Adapter Table Mapping question vs2005

I would like to have the user type in a query statement, click on a [Test] button and have the query results show in a datagrid.

I'm stuck on the data adapter.TableMappings.  This changes depending on the query the user inputs.
Thanks, MikeD

   dsQueryResult = new System.Data.DataSet();
   daQueryResult = new System.Data.SqlClient.SqlDataAdapter();
   myCmd = new SqlCommand();
   
   string cmdStr = "Select * from myTable";
   myCmd.CommandText = cmdStr;
   dsQueryResult .SelectCommand = myCmd;

   daQueryResult .TableMappings.Add()  <==== What goes here

    // Tell the DataAdapter object to fill the DataSet
    daQueryResult .Fill(dsQueryResult );








Answer this question

Data Adapter Table Mapping question vs2005

  • datapvs

    Thank you SirajLala,

    That solves a big question for me.
    I will test it.

    Mike

  • Matt Bamberger

    It is not mandatory to add TableMappings. Even without adding the TableMappings, the Fill will work. However, after the Fill, the name of the Table (and columns in the table) inside the Dataset will be as returned by the backend (Database) server. The TableMappings gives you flexibility of renaming the tables/columns when they get loaded into the Dataset. So, if you can live with the Datagrid showing the name of the Tables/Columns exactly as returned by the server then you can omit specifying the Table/Column Mappings.

  • Data Adapter Table Mapping question vs2005