Click to See Complete Forum and Search --> : reading the result set from a function call


JVisconti
November 16th, 2009, 02:42 PM
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.

BigEd781
November 16th, 2009, 02:46 PM
Hard to say since I have no clue as to what GetStoresListSicom() returns, but a literal translation would be:


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.

JVisconti
November 16th, 2009, 02:56 PM
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?

JVisconti
November 16th, 2009, 02:59 PM
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?

BigEd781
November 16th, 2009, 03:03 PM
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.

JVisconti
November 16th, 2009, 03:08 PM
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!

BigEd781
November 16th, 2009, 03:16 PM
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?

JVisconti
November 16th, 2009, 03:21 PM
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.