473,385 Members | 1,829 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Error about object array converting

Hi,everyone,
I met a trouble,could you give me some useful hints,thank you very much!

===========error message:

Unable to cast object of type 'System.Object[]' to type
'System.Data.OleDb.OleDbParameter[]'.

==========source code like follow:

StringBuilder sbSQL = new StringBuilder();
ArrayList alParameters = new ArrayList();

sbSQL.Append(SQL_SELECT_ALL_TRANSFERS);

if ( ( aAccountNumber != null ) && ( aAccountNumber.Trim().Length > 0 ) )
{
sbSQL.Append(" and (AccountNumber = ?)");
alParameters.Add(OLEDBHelper.MakeInParam("@Account Number",
aAccountNumber));
}

// aPayDateTime
if ( aPayDateTime != DateTime.MinValue )
{
sbSQL.Append(" and (PayDateTime >= ?)");
alParameters.Add(OLEDBHelper.MakeInParam("@PayDate Time",
aPayDateTime.ToString("yyyyMMddHHmmss")));
}

// aPayAmount
if ( aPayAmount != -1 )
{
sbSQL.Append(" and (PayAmount >= ?)");
alParameters.Add(OLEDBHelper.MakeInParam("@PayAmou nt", aPayAmount));
}

// importance:error occured here
OleDbParameter[] inParameters = (OleDbParameter[])alParameters.ToArray();

Dec 12 '05 #1
2 1502
OleDbParameter[] inParameters = new OleDbParameter[alParameters.Count];
alParameters.CopyTo(inParameters);

If you're using .NET 2.0, you can easily use List<OleDbParameter>
inParameters and inParameters.ToArray() as you did with the ArrayList.

Michael

"Ñ©ÔÆÓ¥" <xu********@hotmail.com> schrieb im Newsbeitrag
news:uG**************@TK2MSFTNGP09.phx.gbl...
Hi,everyone,
I met a trouble,could you give me some useful hints,thank you very much!

===========error message:

Unable to cast object of type 'System.Object[]' to type
'System.Data.OleDb.OleDbParameter[]'.

==========source code like follow:

StringBuilder sbSQL = new StringBuilder();
ArrayList alParameters = new ArrayList();

sbSQL.Append(SQL_SELECT_ALL_TRANSFERS);

if ( ( aAccountNumber != null ) && ( aAccountNumber.Trim().Length > 0 ) )
{
sbSQL.Append(" and (AccountNumber = ?)");
alParameters.Add(OLEDBHelper.MakeInParam("@Account Number",
aAccountNumber));
}

// aPayDateTime
if ( aPayDateTime != DateTime.MinValue )
{
sbSQL.Append(" and (PayDateTime >= ?)");
alParameters.Add(OLEDBHelper.MakeInParam("@PayDate Time",
aPayDateTime.ToString("yyyyMMddHHmmss")));
}

// aPayAmount
if ( aPayAmount != -1 )
{
sbSQL.Append(" and (PayAmount >= ?)");
alParameters.Add(OLEDBHelper.MakeInParam("@PayAmou nt", aPayAmount));
}

// importance:error occured here
OleDbParameter[] inParameters = (OleDbParameter[])alParameters.ToArray();

Dec 12 '05 #2
Ñ©ÔÆÓ¥ wrote:
I met a trouble,could you give me some useful hints,thank you very much!
<snip>
// importance:error occured here
OleDbParameter[] inParameters = (OleDbParameter[])alParameters.ToArray();


Use alParameters.ToArray(typeof(OleDbParameter));

Jon

Dec 12 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Russell E. Owen | last post by:
I'm writing a C extension for numarray and am puzzled about the idiom for error handling. The documentation seems to say one should always decref an array after calling NA_InputArray, etc., to...
7
by: Brian P | last post by:
I am getting an invalid cast exception when I try to take an ArrayList with datetime values and use the ToArray method to create an object array. I need to use an object array becase I'm working...
38
by: VK | last post by:
Hello, In my object I have getDirectory() method which returns 2-dimentional array (or an imitation of 2-dimentional array using two JavaScript objects with auto-handled length property - please...
9
by: Eric Lilja | last post by:
Hello, I'm a novice C++ programmer and now I have the task of converting a number of C++ functions to C. Some of the functions I'm converting takes a parameter of type reference-to-std::string...
1
by: amitbadgi | last post by:
I am gettign this error while converting an asp application to asp.net , its a query syntax error, Exception Details: System.Runtime.InteropServices.COMException: Syntax error in query expression...
4
by: Clark Stevens | last post by:
I have a program that I'm converting from VB6 to VB.NET. It reads in a text file containing barcode numbers and their corresponding descriptions. Then the user enters the barcode number and the...
0
by: HKSHK | last post by:
This list compares the error codes used in VB.NET 2003 with those used in VB6. Error Codes: ============ 3: This Error number is obsolete and no longer used. (Formerly: Return without GoSub)...
4
by: | last post by:
Hi all, I want to create a method that does the following: 1) Programmatically instantiate a new XmlDataSource control 2) For each file in a named directory, make a "FileSystemItem" element 3)...
5
by: Al G | last post by:
Hi, I'm converting a bit of POP3 VB6 code to VB2005, and have run into this error with the following code. Can someone help me find out what I'm missing/doing wrong? 'holds the attachments...
63
by: Kapteyn's Star | last post by:
Hi newsgroup The program here given is refused by GCC with a error i cannot understand. It says rnd00.c: In function ‘main’: rnd00.c:26: error: expected expression before ‘]’ token ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.