I'm going from VB to C#.
I have example in VB:
Dim myParams As New Collection
Dim par 1 as SqlParameter
par1 = New SqlParameter("@mediaId", SqlDbType.NVarChar, 10)
par1.Value = lstMedia.Items(lstMedia.SelectedIndex).Value
myParams.Add(par1)
I would like to do the similar in C#:
SqlParameterCollection[] myParams=new SqlParameterCollection[3];
SqlParameter par1;
par1 = new SqlParameter("@mediaId", SqlDbType.NVarChar, 10);
par1.Value = lstMedia.Items[lstMedia.SelectedIndex].Value;
myParams.Add(par1); - - there is no ADD method ?
Any solution?
Regards,Simon 6 3705
So you want an array of collections? Any particular reason why?
SqlParamaterCollection does not have a publically available constructor so
am I correct in assuming that this is why you are using an array of the
collections?
"simon" wrote: I'm going from VB to C#.
I have example in VB: Dim myParams As New Collection Dim par 1 as SqlParameter
par1 = New SqlParameter("@mediaId", SqlDbType.NVarChar, 10) par1.Value = lstMedia.Items(lstMedia.SelectedIndex).Value myParams.Add(par1)
I would like to do the similar in C#:
SqlParameterCollection[] myParams=new SqlParameterCollection[3]; SqlParameter par1;
par1 = new SqlParameter("@mediaId", SqlDbType.NVarChar, 10); par1.Value = lstMedia.Items[lstMedia.SelectedIndex].Value; myParams.Add(par1); - - there is no ADD method ?
Any solution?
Regards,Simon
SqlParameterCollection[] myParams=new SqlParameterCollection[3];
A fixed array doesn't have a .Add method because it is "fixed".
You can do:
par1 = new SqlParameter("@mediaId", SqlDbType.NVarChar, 10);
par1.Value = lstMedia.Items[lstMedia.SelectedIndex].Value;
replace
myParams.Add(par1); - - there is no ADD method ?
by
myParams[i] = par1; // where i is from the index (0 to 2 ) of yours fixed
array.
The best solution.
Replace:
SqlParameterCollection[] myParams=new SqlParameterCollection[3];
by
SqlParameterCollection myParams=new ArrayList();
then you can use
myParams.Add(par1); - now there is ADD method!!!
Gustavo.
"Brian Delahunty" <Br************@discussions.microsoft.com> wrote in
message news:F8**********************************@microsof t.com... So you want an array of collections? Any particular reason why?
SqlParamaterCollection does not have a publically available constructor so am I correct in assuming that this is why you are using an array of the collections?
"simon" wrote:
I'm going from VB to C#.
I have example in VB: Dim myParams As New Collection Dim par 1 as SqlParameter
par1 = New SqlParameter("@mediaId", SqlDbType.NVarChar, 10) par1.Value = lstMedia.Items(lstMedia.SelectedIndex).Value myParams.Add(par1)
I would like to do the similar in C#:
SqlParameterCollection[] myParams=new SqlParameterCollection[3]; SqlParameter par1;
par1 = new SqlParameter("@mediaId", SqlDbType.NVarChar, 10); par1.Value = lstMedia.Items[lstMedia.SelectedIndex].Value; myParams.Add(par1); - - there is no ADD method ?
Any solution?
Regards,Simon
this is a more elegant solution:
try this and let me know if it works.
public class MyComparer2 : IComparer
{
private SortedList mSortedList;
public SortedList SortedList
{
get{return mSortedList;}
set{mSortedList = value;}
}
int IComparer.Compare(Object x, Object y)
{
int keyLeft = (int) x;
int keyRight = (int) y;
return((new CaseInsensitiveComparer()).Compare(mSortedList[y],
mSortedList[x]));
}
}
public void test()
{
MyComparer2 comparer = new MyComparer2();
SortedList sortedList = new SortedList(comparer);
comparer.SortedList = sortedList;
sortedList.Add(1,3);
sortedList.Add(2,4);
sortedList.Add(3,2);
sortedList.Add(4,5);
sortedList.Add(5,1);
//Here we look for keys....
Console.WriteLine(sortedList[3]); // the return object is "2";
//The SortedList was dinamically sorted by the second column when the items
are loaded.
foreach(int i in sortedList.Keys)
Console.WriteLine("Index:" + sortedList.IndexOfKey(i) + " Key:" + i + "
Value:" + sortedList[i]);
//It should shows
//Index:1 Key: 5 Value: 1
//Index:2 Key: 3 Value: 2
//Index:3 Key: 1 Value: 3
//Index:4 Key: 2 Value: 4
//Index:5 Key: 4 Value: 5
}
Gustavo
"Franco, Gustavo" <gustavo_franco[REMOVEIT]@hotmail.com> wrote in message
news:Or****************@TK2MSFTNGP15.phx.gbl... SqlParameterCollection[] myParams=new SqlParameterCollection[3];
A fixed array doesn't have a .Add method because it is "fixed".
You can do:
par1 = new SqlParameter("@mediaId", SqlDbType.NVarChar, 10); par1.Value = lstMedia.Items[lstMedia.SelectedIndex].Value; replace myParams.Add(par1); - - there is no ADD method ? by myParams[i] = par1; // where i is from the index (0 to 2 ) of yours fixed array.
The best solution.
Replace: SqlParameterCollection[] myParams=new SqlParameterCollection[3]; by SqlParameterCollection myParams=new ArrayList(); then you can use myParams.Add(par1); - now there is ADD method!!!
Gustavo.
"Brian Delahunty" <Br************@discussions.microsoft.com> wrote in message news:F8**********************************@microsof t.com... So you want an array of collections? Any particular reason why?
SqlParamaterCollection does not have a publically available constructor so am I correct in assuming that this is why you are using an array of the collections?
"simon" wrote:
I'm going from VB to C#.
I have example in VB: Dim myParams As New Collection Dim par 1 as SqlParameter
par1 = New SqlParameter("@mediaId", SqlDbType.NVarChar, 10) par1.Value = lstMedia.Items(lstMedia.SelectedIndex).Value myParams.Add(par1)
I would like to do the similar in C#:
SqlParameterCollection[] myParams=new SqlParameterCollection[3]; SqlParameter par1;
par1 = new SqlParameter("@mediaId", SqlDbType.NVarChar, 10); par1.Value = lstMedia.Items[lstMedia.SelectedIndex].Value; myParams.Add(par1); - - there is no ADD method ?
Any solution?
Regards,Simon
Sorry wrong Post
Gustavo
"Franco, Gustavo" <gustavo_franco[REMOVEIT]@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP09.phx.gbl... this is a more elegant solution:
try this and let me know if it works.
public class MyComparer2 : IComparer { private SortedList mSortedList;
public SortedList SortedList { get{return mSortedList;} set{mSortedList = value;} }
int IComparer.Compare(Object x, Object y) { int keyLeft = (int) x; int keyRight = (int) y; return((new CaseInsensitiveComparer()).Compare(mSortedList[y], mSortedList[x])); } }
public void test() { MyComparer2 comparer = new MyComparer2(); SortedList sortedList = new SortedList(comparer); comparer.SortedList = sortedList;
sortedList.Add(1,3); sortedList.Add(2,4); sortedList.Add(3,2); sortedList.Add(4,5); sortedList.Add(5,1);
//Here we look for keys.... Console.WriteLine(sortedList[3]); // the return object is "2";
//The SortedList was dinamically sorted by the second column when the items are loaded. foreach(int i in sortedList.Keys) Console.WriteLine("Index:" + sortedList.IndexOfKey(i) + " Key:" + i + " Value:" + sortedList[i]);
//It should shows //Index:1 Key: 5 Value: 1 //Index:2 Key: 3 Value: 2 //Index:3 Key: 1 Value: 3 //Index:4 Key: 2 Value: 4 //Index:5 Key: 4 Value: 5 }
Gustavo
"Franco, Gustavo" <gustavo_franco[REMOVEIT]@hotmail.com> wrote in message news:Or****************@TK2MSFTNGP15.phx.gbl... SqlParameterCollection[] myParams=new SqlParameterCollection[3];
A fixed array doesn't have a .Add method because it is "fixed".
You can do:
par1 = new SqlParameter("@mediaId", SqlDbType.NVarChar, 10); par1.Value = lstMedia.Items[lstMedia.SelectedIndex].Value; replace myParams.Add(par1); - - there is no ADD method ? by myParams[i] = par1; // where i is from the index (0 to 2 ) of yours fixed array.
The best solution.
Replace: SqlParameterCollection[] myParams=new SqlParameterCollection[3]; by SqlParameterCollection myParams=new ArrayList(); then you can use myParams.Add(par1); - now there is ADD method!!!
Gustavo.
"Brian Delahunty" <Br************@discussions.microsoft.com> wrote in message news:F8**********************************@microsof t.com... So you want an array of collections? Any particular reason why?
SqlParamaterCollection does not have a publically available constructor so am I correct in assuming that this is why you are using an array of the collections?
"simon" wrote:
I'm going from VB to C#.
I have example in VB: Dim myParams As New Collection Dim par 1 as SqlParameter
par1 = New SqlParameter("@mediaId", SqlDbType.NVarChar, 10) par1.Value = lstMedia.Items(lstMedia.SelectedIndex).Value myParams.Add(par1)
I would like to do the similar in C#:
SqlParameterCollection[] myParams=new SqlParameterCollection[3]; SqlParameter par1;
par1 = new SqlParameter("@mediaId", SqlDbType.NVarChar, 10); par1.Value = lstMedia.Items[lstMedia.SelectedIndex].Value; myParams.Add(par1); - - there is no ADD method ?
Any solution?
Regards,Simon
Thank you Franco,
If I replace like you said
SqlParameterCollection myParams=new ArrayList();
I get an error:
"Cannot implicitly convert type 'System.Collections.ArrayList' to
'System.Data.SqlClient.SqlParameterCollection' "
Why?
But it works if I do:
ArrayList() myParams=new ArrayList();
Regards,Simon
"Franco, Gustavo" <gustavo_franco[REMOVEIT]@hotmail.com> wrote in message
news:Or****************@TK2MSFTNGP15.phx.gbl... SqlParameterCollection[] myParams=new SqlParameterCollection[3];
A fixed array doesn't have a .Add method because it is "fixed".
You can do:
par1 = new SqlParameter("@mediaId", SqlDbType.NVarChar, 10); par1.Value = lstMedia.Items[lstMedia.SelectedIndex].Value; replace myParams.Add(par1); - - there is no ADD method ? by myParams[i] = par1; // where i is from the index (0 to 2 ) of yours fixed array.
The best solution.
Replace: SqlParameterCollection[] myParams=new SqlParameterCollection[3]; by SqlParameterCollection myParams=new ArrayList(); then you can use myParams.Add(par1); - now there is ADD method!!!
Gustavo.
"Brian Delahunty" <Br************@discussions.microsoft.com> wrote in message news:F8**********************************@microsof t.com... So you want an array of collections? Any particular reason why?
SqlParamaterCollection does not have a publically available constructor so am I correct in assuming that this is why you are using an array of the collections?
"simon" wrote:
I'm going from VB to C#.
I have example in VB: Dim myParams As New Collection Dim par 1 as SqlParameter
par1 = New SqlParameter("@mediaId", SqlDbType.NVarChar, 10) par1.Value = lstMedia.Items(lstMedia.SelectedIndex).Value myParams.Add(par1)
I would like to do the similar in C#:
SqlParameterCollection[] myParams=new SqlParameterCollection[3]; SqlParameter par1;
par1 = new SqlParameter("@mediaId", SqlDbType.NVarChar, 10); par1.Value = lstMedia.Items[lstMedia.SelectedIndex].Value; myParams.Add(par1); - - there is no ADD method ?
Any solution?
Regards,Simon
Sorry it was a typo error.
I replied the email without analyze the code.
You have a problem there.
You are creating a fixed array with dimension 3 of collections
(SqlParameterCollection[] myParams=new SqlParameterCollection[3]). I guess
you did that because SqlParameterCollection doesn't have a default
constructors, but that doesn't mean you are creating an instance to
SqlParameterCollection, it just creates 3 pointers or references to
SqlParameterCollection objects;
Basically, I see you can't use SqlParameterCollection and it is used for
..net framework to return to you a collection of parameters from same another
method.
ArrayList myParams=new ArrayList();
SqlParameter par1;
par1 = new SqlParameter("@mediaId", SqlDbType.NVarChar, 10);
par1.Value = lstMedia.Items[lstMedia.SelectedIndex].Value;
myParams.Add(par1);
This is the code that you are looking for.
Why this doesn't work?
SqlParameterCollection myParams=new ArrayList();
SqlParameterCollection and ArrayList are two totally different classes, so
ArrayList can't be "cast" to SqlParameterCollection.
It is like having a square and a circle both having the same surface and
trying to fit the square inside the circle.
Gustavo
"simon" <si*********@stud-moderna.si> wrote in message
news:uz*************@TK2MSFTNGP09.phx.gbl... Thank you Franco,
If I replace like you said
SqlParameterCollection myParams=new ArrayList();
I get an error:
"Cannot implicitly convert type 'System.Collections.ArrayList' to 'System.Data.SqlClient.SqlParameterCollection' "
Why?
But it works if I do:
ArrayList() myParams=new ArrayList();
Regards,Simon
"Franco, Gustavo" <gustavo_franco[REMOVEIT]@hotmail.com> wrote in message news:Or****************@TK2MSFTNGP15.phx.gbl... SqlParameterCollection[] myParams=new SqlParameterCollection[3];
A fixed array doesn't have a .Add method because it is "fixed".
You can do:
par1 = new SqlParameter("@mediaId", SqlDbType.NVarChar, 10); par1.Value = lstMedia.Items[lstMedia.SelectedIndex].Value; replace myParams.Add(par1); - - there is no ADD method ? by myParams[i] = par1; // where i is from the index (0 to 2 ) of yours fixed array.
The best solution.
Replace: SqlParameterCollection[] myParams=new SqlParameterCollection[3]; by SqlParameterCollection myParams=new ArrayList(); then you can use myParams.Add(par1); - now there is ADD method!!!
Gustavo.
"Brian Delahunty" <Br************@discussions.microsoft.com> wrote in message news:F8**********************************@microsof t.com... So you want an array of collections? Any particular reason why?
SqlParamaterCollection does not have a publically available constructor so am I correct in assuming that this is why you are using an array of the collections?
"simon" wrote:
I'm going from VB to C#.
I have example in VB: Dim myParams As New Collection Dim par 1 as SqlParameter
par1 = New SqlParameter("@mediaId", SqlDbType.NVarChar, 10) par1.Value = lstMedia.Items(lstMedia.SelectedIndex).Value myParams.Add(par1)
I would like to do the similar in C#:
SqlParameterCollection[] myParams=new SqlParameterCollection[3]; SqlParameter par1;
par1 = new SqlParameter("@mediaId", SqlDbType.NVarChar, 10); par1.Value = lstMedia.Items[lstMedia.SelectedIndex].Value; myParams.Add(par1); - - there is no ADD method ?
Any solution?
Regards,Simon
This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Generic Usenet Account |
last post by:
To settle the dispute regarding what happens when an "erase" method is
invoked on an STL container (i.e. whether the element is merely
removed from the container or whether it also gets deleted in...
|
by: Kurt Bauer |
last post by:
I have an ASP group calendar application which pulls calendar data from
Exchange via webdav into an XML string. I then loop the XML nodes to
populate a collection of appointments. Finally I use...
|
by: Scott |
last post by:
I have a collection where the items in the collection are dates. I want to
iterate over the collection and build a value list string for the rowsource
of a listbox. The dates in the collection are...
|
by: Pavils Jurjans |
last post by:
Hello,
There's some confusion about the purpose and difference between these handy
classes...
First, both of them are holding number of key - value pairs, right? Then, I
see that there may be...
|
by: Edward Diener |
last post by:
In C++ an overridden virtual function in a derived class must have the exact
same signature of the function which is overridden in the base class, except
for the return type which may return a...
|
by: Brian |
last post by:
NOTE ALSO POSTED IN
microsoft.public.dotnet.framework.aspnet.buildingcontrols
I have solved most of my Server Control Collection property issues.
I wrote an HTML page that describes all of the...
|
by: Matt Michael |
last post by:
I have a listview control and a collection object right now that I'm trying
to pass information to and from. Whenever I click on the checkbox, I want
it to remove certain listview items and add...
|
by: Chet Cromer |
last post by:
I am creating a set of base classes and sub classes to use throughout a
program I'm developing. The base class represents a generic "lookup
table" from my database that contains lists of things...
|
by: Scott M. Lyon |
last post by:
As I mentioned in my other post, I'm attempting to, using COM Interop so I
can update existing VB6 code to (for several specific functions) return a
Hashtable from a .NET library.
I've had...
|
by: Arthur Dent |
last post by:
How do you sort a generic collection derived from
System.Collections.ObjectModel.Collection?
Thanks in advance,
- Arthur Dent
|
by: CloudSolutions |
last post by:
Introduction:
For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome former...
|
by: ryjfgjl |
last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
|
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,...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
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
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
| |