I am just learning Datasets, and as luck ALWAYS has it can not start out simple. I am pulling from an ODBC file which can be connected to on the Dataserver or Table adaptor, but then they come in with no tables.
So I am forced to work with runtime datasets. My first attempt is interesting. I created one SQL statement.. If put into a Datareader it works fine. If put into a Strong typed dataset (either built in the Dataset Designer window or built with a Fillschema) I get nothing. But if I put it to an untyped dataset I pull the info.
Here's the questions that my studies have not answered.
Does the strong Typed column field names HAVE to match the names in the DataAdaptor?.. I guess my fillschema would, but my other one does not since the SQL statement is a cross join, so the column names are TR.CustomerID,TR.TranNumber etc.. (as shown with the display of the untyped Dataset that pulls info).. I would prefer to have them move into fields simply labeled CustomerID, TranNumber..
Here is an example of one of the two Typed Datasets that is missing info.. Do you see anything that maybe the typed DS needs the untyped did not?
InitializeComponent();
// create an OdbcConnection object and connect it to our sample data source
OdbcConnection DbConnection = new OdbcConnection("Provider=MSDASQL.1;DSN=Vision Data;UID=user;PWD=pswd");
// Using that command, we can issue a Query and create an OdbcDataReader:
string strSQL = "SELECT TR.Tran_num, AM.Acct_no, AM.Cust_type ”
+ "FROM artransaction TR "
+ "INNER JOIN armaster AM ON TR.Acct_no = AM.Acct_no "
+ "WHERE TR.Profit_no = 1 and TR.Tran_num = 842049";
OdbcDataAdapter da = new OdbcDataAdapter(strSQL, DbConnection);
//DataSet ds = new DataSet("dsarTransaction");
dsTestDS1 ds = new dsTestDS1();
// need to move Table adaptor info into the dataset HERE
// fields typed in the dataset designer does not work.
da.Fill(ds, "typedDS");
if (ds.HasChanges())
{
CreateViewer(ds.Tables[0]);
}
DataTableReader dr = ds.CreateDataReader(ds.Tables[0]);
dr = ds.CreateDataReader(ds.Tables[0]);
MessageBox.Show("Dataset contains " + dr.FieldCount.ToString() + " Fields " +
" and " + dr.RecordsAffected.ToString() + " Records ");
while (dr.Read())
{
MessageBox.Show(dr.GetInt32(0).ToString());
}