CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8
  1. #1
    Join Date
    Nov 2009
    Posts
    18

    reading the result set from a function call

    I have a function called GetStoresListSicom() and I am trying to convert some of the code relating to this function from VB to C#. Here is the original vb code:

    rst = obj.GetStoresListSicom()
    If rst.BOF() Or rst.EOF() Then
    Else

    rst.movefirst()
    ctr = 0
    While Not rst.EOF

    sStore = rst("store_code").value

    I need to convert this into the related code in C#. Any advice would be greatly appreciated.

  2. #2
    Join Date
    Jun 2008
    Posts
    2,477

    Re: reading the result set from a function call

    Hard to say since I have no clue as to what GetStoresListSicom() returns, but a literal translation would be:

    Code:
    rst = obj.GetStoresListSicon( );
    if ( !rst.BOF( ) && !rst.EOF( ) )
    {
        rst.MoveFirst( );
        int ctr = 0;  // this is not used at all, so remove it
        while ( !rst.EOF( ) )
        {
            sStore = rst("store_code").Value;
        }
    }
    That is a very strange little snippet. It looks like you should just be iterating over the result in a foreach loop, and 'ctr' is never used.
    Last edited by BigEd781; November 16th, 2009 at 04:02 PM.

  3. #3
    Join Date
    Nov 2009
    Posts
    18

    Re: reading the result set from a function call

    The GetStoresListSicom function makes a call to a Stored Procedure that returns a recordset from a table in SQL. The whole portion of the program I have was written in VB and VS2002, but I need to be able to use SFTP, and so it's getting migrated to C# and VS2005. the ctr isn't used in this function it is referenced in other parts of the program, so I need to leave it in there. Would a foreach loop really work better than an if statement?

  4. #4
    Join Date
    Nov 2009
    Posts
    18

    Re: reading the result set from a function call

    I seem to also have an issue when further up in the code I make the call to GetStoresListSicom from a button click event. It gives me an error that the method doesn't accept 0 arguments, but I am only making a call to that function. Any input?

  5. #5
    Join Date
    Jun 2008
    Posts
    2,477

    Re: reading the result set from a function call

    The iterative approach would only work if the object implements IEnumerable or exposes some way to retrieve consecutive elements. I have never dealt with a RecordSet, so I have no clue if this would work for you, I just translated the syntax.

    As far as the error goes, I don't know what to tell you. If the compiler thinks that the function takes an argument, it does.

  6. #6
    Join Date
    Nov 2009
    Posts
    18

    Re: reading the result set from a function call

    The error just disappeared when I added the code you suggested. I have one more thing to work out, and the code should run like it did in VB. Thank you for the help!

  7. #7
    Join Date
    Jun 2008
    Posts
    2,477

    Re: reading the result set from a function call

    Quote Originally Posted by JVisconti View Post
    The error just disappeared when I added the code you suggested. I have one more thing to work out, and the code should run like it did in VB. Thank you for the help!
    Well, I just translated exactly what you had posted, only you can know the semantics of your application. Are you a professional software developer?
    Last edited by BigEd781; November 16th, 2009 at 04:32 PM.

  8. #8
    Join Date
    Nov 2009
    Posts
    18

    Re: reading the result set from a function call

    I am a starting programmer, I'm getting a semi trial by fire in the professional programming world, but I enjoy coding alot. I was handed this project from someone else. The original code just needed to do a regular ftp transfer, but the requirements changed and now they need SFTP, so the decision was made to create a component in VS2005 to do the SFTP and reference it in the original VS2002 project. I'm just trying to make it work.
    Last edited by JVisconti; November 16th, 2009 at 04:43 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured