471,627 Members | 2,370 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,627 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 1466
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

8 posts views Thread by Russell E. Owen | last post: by
1 post views Thread by amitbadgi | last post: by
63 posts views Thread by Kapteyn's Star | last post: by
1 post views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by

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.