OledbDataAdapter.fill problem - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

OledbDataAdapter.fill problem

kikijaskikijas Posts: 12Member
Hi, I am having problem to read data from the datasource through the OledbDataAdapter as shown in the code below:
Let say I have a table "TableB" in dataset "dset", with the data of "000" and "001" in "col1" column. I expected in the for loop below, the "TableA" will be filled with the data extracted out from the database where AData.SN = 001 (in first loop) and 002 (in second loop). However, it did not. The data extracted from the first loop is being filled in repeatedly to the "TableA" of dataset DS. Can anyone see the problem here? Please help to advise, thank you.

for (int i = 0; i < dset.Tables["TableB"].Rows.Count; i++)
{
DataRow drow;
drow = dset.Tables["TableB"].Rows[i];
string srNum = drow["col1"].ToString();

dadpmod.SelectCommand.CommandText = "select AData.*, " +
"data.*, car.* from (AData inner join data " +
"on AData.A = data.B ) inner join " +
"car on car.type = data.type " +
"where AData.SN = @sn";
dadpmod.SelectCommand.Parameters.Add(new OleDbParameter("sn", srNum));

dadpmod.Fill(DS, "TableA");
}

Comments

  • bradwangbradwang Posts: 197Member
    : Hi, I am having problem to read data from the datasource through the
    : OledbDataAdapter as shown in the code below:
    : Let say I have a table "TableB" in dataset "dset", with the data of
    : "000" and "001" in "col1" column. I expected in the for loop below,
    : the "TableA" will be filled with the data extracted out from the
    : database where AData.SN = 001 (in first loop) and 002 (in second
    : loop). However, it did not. The data extracted from the first loop
    : is being filled in repeatedly to the "TableA" of dataset DS. Can
    : anyone see the problem here? Please help to advise, thank you.
    :
    : for (int i = 0; i < dset.Tables["TableB"].Rows.Count; i++)
    : {
    : DataRow drow;
    : drow = dset.Tables["TableB"].Rows[i];
    : string srNum = drow["col1"].ToString();
    :
    : dadpmod.SelectCommand.CommandText = "select AData.*, " +
    : "data.*, car.* from (AData inner join data " +
    : "on AData.A = data.B ) inner join " +
    : "car on car.type = data.type " +
    : "where AData.SN = @sn";
    : dadpmod.SelectCommand.Parameters.Add(new OleDbParameter("sn",
    : srNum));
    :
    : dadpmod.Fill(DS, "TableA");
    : }


    Hello, your code has some logic issue, you're running a loop and I'm quite sure that you want to get a series of data table being filled after the loop. However, you are running code: [italic]dadpmod.Fill(DS, "TableA"); [/italic]which make the table "TableA" being fill repeatedly.


    I suggest you to write it like:
    [italic]dadpmod.Fill(DS, "TableA"+i.ToString());[/italic]
    So that you will get a series of data table filled after running the loop, data table names will be like: TableA0, TableA1, TableA2...

    Hope this helps and happy coding. :)





    Brad Wang
    .NET Freelancer from China
Sign In or Register to comment.