Can someone look at my code below and tell me what I'm doing wrong I converted VBScript to C# for ASP to ASP.NET migration. (I wasn't able to successfully convert legacy ADO to ADO.NET, so sticking with this) I'm getting an error at this line:
cartValues = RS.GetRows(-1, null, null);
Error Message:
Exception Details: System.Runtime.InteropServices.COMException: Application uses a value of the wrong type for the current operation.
C# Code:
ADODB.ConnectionClass con;
object[] arrVals;
string sqlStr;
ADODB.Recordset RS;
object cartValues;
int i = 0;
con = new ADODB.ConnectionClass();
con.Open("Provider=SQLOLEDB;Data Source=xxx.xxx.xxx.xxx; Network Library=DBMSSOCN; Initial Catalog=xxx;User ID=xxx;Password=xxx;", "", "", -1);
arrVals = Request.QueryString["chkBox"].Split(',');
sqlStr = "SELECT PublicationsID, title, url, price, MaxOrder, qty, govtpubnumber, image, TitleDisplay, CategoryID FROM Publications WHERE ";
for (i = 0; i <= arrVals.GetUpperBound(0); i++)
{
if (i == 0)
sqlStr = sqlStr + "PublicationsID = " + arrVals
;
else
{
sqlStr = sqlStr + " OR PublicationsID = " + arrVals
;
}
}
sqlStr = sqlStr + " ORDER BY CategoryID, title ";
//Response.Write(sqlStr);
Object RecordsAffected = null;
RS = con.Execute(sqlStr, out RecordsAffected, -1);
cartValues = RS.GetRows(-1, null, null);
Session.Add("cart", cartValues);
RS = null;
con.Close();
I tried converting the original code from VBScript to VB.NET first and it worked fine with no arguments in the GetRows method: cartValues = RS.GetRows(). I found that this method has three arguments and they are all optional in VB but not in C#:
arrayName = Recordset.GetRows(int Rows, object Start, object Fields )
In VB when no arguments are specified, it returns all rows starting from the current row. I need to get the behavior in C#, but I'm not sure what to put in to the second and third arguments. Please help anyone.

GetRows Method works in VB but not in C#
Mehmet ECEV&#304;T
Rather than attempting to use legacy components (ADO) in .NET, perhaps you should investigate and look at using ADO.NET.
By-the-way, in C# you can pass Type.Missing in place of optional arguments.
moflaherty
subansuba
Interesting...
We use "System.Reflection.Missing.Value" in our conversions, but my test just now shows that "System.Type.Missing" resolves to exactly the same thing (if you output the 'ToString' of each, they both show "System.Reflection.Missing").
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# Converter
Instant VB: C# to VB Converter
Instant C++: C# to C++ and VB to C++ Converter
Instant J#: VB to J# Converter
Clear VB: Cleans up VB code
Clear C#: Cleans up C# code
si downes