Dataset problem, please help

  • Thread starter Thread starter pei_world
  • Start date Start date
P

pei_world

the following codes are error occurs.
basically, I set a breakpoint at BuildingTN, I trace it, and it come up my
intended table, but when I run the program, in my component cobInside, it
always displays somethings from my other table.


DataSet ds = officeAux.DSource;
officeAux.DA.Fill(ds,BuildingTN);

for(int i=0;i<ds.Tables[BuildingTN].Rows.Count;i++)
{
this.cobInside.Items.Add(ds.Tables[BuildingTN].Rows.ItemArray[1]);
}

does anyone know what happen??

pei
 
The DataAdapter object's Fill method is overloaded.
You can supply a DataTable rather than a DataSet.
Or, you can supply a DataSet and a string for the
name of the DataTable you want to populate or create, as shown here:

intRowsRetrieved = da.Fill(ds, "Customers");
intRowsRetrieved = da.Fill(ds.Tables("Customers"));
intRowsRetrieved = da.Fill(ds, 11, 10, "Customers");

Looks to me like you are calling the DataSet "BuildingTN" in your code.

Try using soemthing like this to test it out:

this.cobInside.Items.Add(ds.Tables[0].Rows.ItemArray

-- where [0] is the ordinal of the table in the multi-table DataSet

--Peter
 
DataSet ds = officeAux.DSource;
officeAux.DA.Fill(ds,BuildingTN);

for(int i=0;i<ds.Tables[BuildingTN].Rows.Count;i++)
{
this.cobInside.Items.Add(ds.Tables[BuildingTN].Rows.ItemArray[1]);
}

MessageBox.Show(ds.Tables.Count.ToString()+" "+ds.Tables[1].ToString()+"
"+ds.Tables[BuildingTN].TableName);


from the last MessageBox dialog, it shows the name of table I am accessing
is correct. but just don't know why it use the wrong table,so that it means
dataset contains 2 tables, but it can't access the 2nd table.
 
Ok,

for(int i=0;i<ds.tables[buildingTN].rows.count;i++)
unless buildingTN resolved to an integer value,
shouldn't this be:
for(int i=0;i<ds.tables["buildingTN"].rows.count;i++)
-- in other words, unless buildingTN is a variable of type
int, you would need to place inside quotation marks
to reference an "named" table overload. Check your documentation
your only problem at this point appears to be a minor syntax
error.
--Peter




pei_world said:
DataSet ds = officeAux.DSource;
officeAux.DA.Fill(ds,BuildingTN);

for(int i=0;i<ds.Tables[BuildingTN].Rows.Count;i++)
{
this.cobInside.Items.Add(ds.Tables[BuildingTN].Rows.ItemArray[1]);
}

MessageBox.Show(ds.Tables.Count.ToString()+" "+ds.Tables[1].ToString()+"
"+ds.Tables[BuildingTN].TableName);


from the last MessageBox dialog, it shows the name of table I am accessing
is correct. but just don't know why it use the wrong table,so that it means
dataset contains 2 tables, but it can't access the 2nd table.






pei_world said:
the following codes are error occurs.
basically, I set a breakpoint at BuildingTN, I trace it, and it come up my
intended table, but when I run the program, in my component cobInside, it
always displays somethings from my other table.


DataSet ds = officeAux.DSource;
officeAux.DA.Fill(ds,BuildingTN);

for(int i=0;i<ds.Tables[BuildingTN].Rows.Count;i++)
{
this.cobInside.Items.Add(ds.Tables[BuildingTN].Rows.ItemArray[1]);
}

does anyone know what happen??

pei

 
NO, no, no....
even I change the parameter to ds.Tables[1].TableName, it will get me the
index 0 table, I don't know why.
My BuildingTN is the name of my table, it will resolve to my table name. but
even I replace by "tablename", it still give me the other table's data.
don't know why.





Peter Bromberg said:
Ok,

for(int i=0;i<ds.tables[buildingTN].rows.count;i++)
unless buildingTN resolved to an integer value,
shouldn't this be:
for(int i=0;i<ds.tables["buildingTN"].rows.count;i++)
-- in other words, unless buildingTN is a variable of type
int, you would need to place inside quotation marks
to reference an "named" table overload. Check your documentation
your only problem at this point appears to be a minor syntax
error.
--Peter




pei_world said:
DataSet ds = officeAux.DSource;
officeAux.DA.Fill(ds,BuildingTN);

for(int i=0;i<ds.Tables[BuildingTN].Rows.Count;i++)
{
this.cobInside.Items.Add(ds.Tables[BuildingTN].Rows.ItemArray[1]);
}

MessageBox.Show(ds.Tables.Count.ToString()+" "+ds.Tables[1].ToString()+"
"+ds.Tables[BuildingTN].TableName);


from the last MessageBox dialog, it shows the name of table I am accessing
is correct. but just don't know why it use the wrong table,so that it means
dataset contains 2 tables, but it can't access the 2nd table.






pei_world said:
the following codes are error occurs.
basically, I set a breakpoint at BuildingTN, I trace it, and it come
up
my
intended table, but when I run the program, in my component cobInside, it
always displays somethings from my other table.


DataSet ds = officeAux.DSource;
officeAux.DA.Fill(ds,BuildingTN);

for(int i=0;i<ds.Tables[BuildingTN].Rows.Count;i++)
{
this.cobInside.Items.Add(ds.Tables[BuildingTN].Rows.ItemArray[1]);
}

does anyone know what happen??

pei


 
Peter Bromberg said:
for(int i=0;i<ds.tables[buildingTN].rows.count;i++)
unless buildingTN resolved to an integer value,
shouldn't this be:
for(int i=0;i<ds.tables["buildingTN"].rows.count;i++)
-- in other words, unless buildingTN is a variable of type
int, you would need to place inside quotation marks
to reference an "named" table overload. Check your documentation
your only problem at this point appears to be a minor syntax
error.

No, if buildingTN is a string variable it'll be fine too. (I believe
that's the case here).
 
yes, BuildingTN is string type variable. what I want is that obtain two
tables into a dataset and create relation for them. but the BuildingTN
always give me the first table. don't know why table 2 is missing.

thanks


Jon Skeet said:
Peter Bromberg said:
for(int i=0;i<ds.tables[buildingTN].rows.count;i++)
unless buildingTN resolved to an integer value,
shouldn't this be:
for(int i=0;i<ds.tables["buildingTN"].rows.count;i++)
-- in other words, unless buildingTN is a variable of type
int, you would need to place inside quotation marks
to reference an "named" table overload. Check your documentation
your only problem at this point appears to be a minor syntax
error.

No, if buildingTN is a string variable it'll be fine too. (I believe
that's the case here).
 
Back
Top