locked
converting the result of a count query into an int RRS feed

  • Question

  • Hello,

    I have a tableadapter a query etc...
    and when I execute my query with the query builder it gives the correct count result, but when I have this bit of code in my program:
    Code Block

    int EnInEn = Convert.ToInt32(kaartInfoFTableAdapter.FiO(xo, xt, yo, yt, 1));

    it results in a value 0, while in the executed query the value was 3

    How can I solve this problem?

    Thanks in advance,

    Ruben Pieters

    Tuesday, December 25, 2007 11:41 AM

Answers

  • Well I have found the solution to my problem now

    Just had to update the data with this bit of code:

    Code Block

    this.Validate();
    this.kaartInfoBindingSource.EndEdit();
    this.kaartInfoTableAdapter.Update(this.database1DataSet.KaartInfo);


    Thursday, December 27, 2007 8:59 PM

All replies

  •  RubenPieters wrote:

     

    ....and when I execute my query with the query builder it gives the correct count result, but when I have this bit of code in my program:

    int EnInEn = Convert.ToInt32(kaartInfoFTableAdapter.FiO(xo, xt, yo, yt, 1));

    it results in a value 0, while in the executed query the value was 3

    How can I solve this problem?

     

    Interesting problem.  Not enough info or code sample to provide an answer.  What is that custom method that you appear to have added to the TableAdapter?  What type is is returning? 

     

     

    Wednesday, December 26, 2007 3:04 PM
  • Well I've done a bit more research in my program and that's probably not the fault, I'll explain a bit:

    I have a table (KaartInfo) and another one, which is empty (KaartInfoF) but when I click the button I first want to fill it with the rows that are in the table KaartInfo, (I do that with a select query in KaartInfoF) but it uses the standard values, so when I change some values in my program, it doesn't take those changes into consideration.

    So then when running my other count query it is supposed to count the rows where some conditions apply, but they don't in the standard values. Then I thought it was because of the converting to int part, but that has nothing to do with it.

    That leads me to another question though, how can I put all rows from a certain table (KaartInfo) in another (KaartInfo) with the changes that are made inside my program?

    Wednesday, December 26, 2007 3:45 PM
  • Wednesday, December 26, 2007 7:13 PM
  • Thanks for the links, but those didn't really gave me an answer to my question, they tell me how I can create queries, tableadapters etc.

    But what I want to know is when doing a tableadapter select query, which fills data from a table (KaartInfo) into another (KaartInfoF) how I can make it so that the changes are also put in the new table, and that it doesn't put the rows in the new table like it was at the start of the program

    Thursday, December 27, 2007 9:49 AM
  • You have to update them yourself when changes are made.  ???  

     

    A query result is not exactly a database table.  When you "add" rows to the table of returned results, aren't you adding rows to the underlying data source/table for the original query?

     

     

    ...and that it doesn't put the rows in the new table like it was at the start of the program

     

    ??? You lost me here. 

     

    Rudedog

     

    Thursday, December 27, 2007 1:25 PM
  • I'll explain what I want with another example...

     

    ok, so I have two tables, lets call them Table1 and Table2, at the start of the program Table1 has 1 column and two rows with data, first row has '1' and second has '2' as data, the second table (Table2) has the same column, but no data, and also a select query in the tableadapter that selects all data from Table1 and puts it in Table2.

    and, when pressing on a button you change the data of Table1 to: '2' and '3' (instead of '1' and '2'). But it also activates the select query from Table2tableadapter.

     

    What I want to happen is that in Table2 the data '2' and '3' come (the changes) but instead (well in my program) the data '1' and '2' comes in Table2 (the same as in the start of the program).

     

     

    I hope you understand now :x

     

    Ruben Pieters

    Thursday, December 27, 2007 1:38 PM
  • Well I have found the solution to my problem now

    Just had to update the data with this bit of code:

    Code Block

    this.Validate();
    this.kaartInfoBindingSource.EndEdit();
    this.kaartInfoTableAdapter.Update(this.database1DataSet.KaartInfo);


    Thursday, December 27, 2007 8:59 PM
  • Does this mean that your "converting the result of a count query into an int" issue is fixed?

     

    Thursday, December 27, 2007 9:00 PM
  • Yes, every problem I had is fixed now.
    Friday, December 28, 2007 12:47 PM