473,660 Members | 2,445 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cannot apply indexing with [] to an expression of type 'object'

Hi to all...
Thanks for the help...

I want to get the value of the column of dataset into array, but I get this bug.

"Cannot apply indexing with [] to an expression of type 'object'" when biuld.

The code I used to populate the array is:

ColumnNo = from 0 TO count of columns.

AllColumns[ColumnNo] = dataSet11.Emplo yeeSalary.Colum ns[ColumnNo][1];

Thanks for the help.
Nov 16 '05 #1
8 14853
Do you really want to be looking into the DataColumn objects, or are you
after the values on a row? You don't use the Columns member to get at
column *values* for a row of data. I'm not sure what you intend with the
[1] at the end either.

Brad Williams
"Bassem" <ba*******@hotm ail.com> wrote in message
news:6d******** *************** ***@posting.goo gle.com...
Hi to all...
Thanks for the help...

I want to get the value of the column of dataset into array, but I get this bug.
"Cannot apply indexing with [] to an expression of type 'object'" when biuld.
The code I used to populate the array is:

ColumnNo = from 0 TO count of columns.

AllColumns[ColumnNo] = dataSet11.Emplo yeeSalary.Colum ns[ColumnNo][1];

Thanks for the help.

Nov 16 '05 #2
Thanks for your replay,

Simply I want to get the value of the columns in the array I create to
be able to add them in text file.
Thus if you put this line of command in the command windows will give
you the value of the columns.
dataSet11.Emplo yeeSalary.Colum ns[ColumnNo][1]

But if you will get to use it in the editor window to write the code it
will not compile.

This is the problem , the line doesn't work.
Thanks for you.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #3
Bassem bassem <ba*******@hotm ail.com> wrote:
Thanks for your replay,

Simply I want to get the value of the columns in the array I create to
be able to add them in text file.
Thus if you put this line of command in the command windows will give
you the value of the columns.
dataSet11.Emplo yeeSalary.Colum ns[ColumnNo][1]

But if you will get to use it in the editor window to write the code it
will not compile.

This is the problem , the line doesn't work.


You need to give us more information - such as the type of the
EmployeeSalary property and the Columns property, for a start.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #4

Hi Jon,

This is the lines that give to you the information that you want and the
problem I have.

int FoundRec = 0 ;
oleDbDataAdapte r1.SelectComman d.CommandText = "SELECT * FROM
EmployeeSalary WHERE EmployeeName = '"+ txtBox.Text.Tri m() +"' ";
dataSet11.Clear ();
oleDbDataAdapte r1.Fill(dataSet 11, "EmployeeSalary ");
FoundRec = dataSet11.Emplo yeeSalary.Rows. Count;
if (FoundRec > 0)
{
int ColumnsCount = dataSet11.Emplo yeeSalary.Colum ns.Count;
string[] AllColumns = new string[ColumnsCount];
StreamWriter LWriter = File.CreateText (@"C:\Documen ts and
Settings\bassem \Desktop\data.t xt");

for( int ColumnNo = 0 ; ColumnNo < ColumnsCount ; ColumnNo++)
{
//Here is the problem I can't get the value of the collumns in the
created array.
AllColumns[ColumnNo] = dataSet11.Emplo yeeSalary.Colum ns[ColumnNo][1];

}

Thanks.

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #5
Bassem bassem <ba*******@hotm ail.com> wrote:
This is the lines that give to you the information that you want and the
problem I have.
Well, it doesn't give me the information I asked for - namely the type
of EmployeeSalary. It looks like it's probably a DataTable though. Is
it?
//Here is the problem I can't get the value of the collumns in the
created array.
AllColumns[ColumnNo] = dataSet11.Emplo yeeSalary.Colum ns[ColumnNo][1];


The Columns property stores just the columns themselves - I suspect you
want the *rows*, and you fetch a specific column within that:

AllColumns[ColumnNo] = dataSet11.Emplo yeeSalary.Rows[1][ColumnNo];

That's assuming you want row number 1 (which will actually be the
*second* row).

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #6

yes it is a datatable.

Thanks to any one

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #7
Bassem bassem <ba*******@hotm ail.com> wrote:
yes it is a datatable.


So have you tried using the Rows property instead of Columns?

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #8
Thanks Jon.

Yes the right property is the row.
and the right line of code is
AllColumns[ColumnNo] =
dataSet11.Emplo yeeSalary.Rows[0][ColumnNo].ToString();

Thanks a lot.
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #9

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

Similar topics

8
5463
by: baustin75 | last post by:
Posted: Mon Oct 03, 2005 1:41 pm Post subject: cannot mail() in ie only when debugging in php designer 2005 -------------------------------------------------------------------------------- Hello, I have a very simple problem but cannot seem to figure it out. I have a very simple php script that sends a test email to myself. When I debug it in PHP designer, it works with no problems, I get the test email. If
3
14364
by: Karel Vandenhove | last post by:
Hi, I get an error "cannot apply indexing with to an expression of type object" when I try to compile the code below. SSLScannerManager is a COM component. (Used to access fingerprint scanners and developed by neurotechnologija) How does one get an array from a com component?
3
4172
by: klynn | last post by:
I defined a session variable as an array using Session = new string; Later, in my code, I need to set it and sort it. I tried Session = "some string"; My error is "Cannot apply indexing with to an expression of type 'object'. Then, later, I try to use it, and sort on it an get 'cannot convert from 'object' to System.array. what am I doing wrong here?
3
2470
by: Adam J Knight | last post by:
Hi all, I am getting the following error with this if statement.. if(e.Item.DataItem != 2) { } //error Cannot apply indexing with to an expression of type 'object' Can someone fill me in on what is happening?
2
12450
by: Martin Pöpping | last post by:
Hello, I´m getting the above error with following lines of code: SortedList<int, intpreparedConcepts = prepareConcepts(docs); IList<intpreparedKeys = preparedConcepts.Keys; foreach (int key in preparedKeys) { int count = prepareConcepts; if (minThreshold_ count || maxThreshold_ < count)
26
410
by: jacob navia | last post by:
Suppose an implementation where sizeof int == 4 sizeof void * == 8 sizeof long long == 8 When indexing an array array this would mean that arrays are limited to 2GB. To overcome this,
4
4016
by: O.B. | last post by:
I have the following: public class Matrix3D { private const int SIZE = 3; public double matrix = new double; public static Matrix3D operator *(Matrix3D lhs, Matrix3D rhs) { Matrix3D result = new Matrix3D();
4
26425
by: Chiefy | last post by:
C# APP Basically i am trying to use indexing on an array that i have fed into a method as its parameter. Here is a simplified version of my code. public void Inputs(string path) { string line; line = inputstream.ReadToEnd(); string words; char seperators = { '\t', '\n' }; words = line.Split(seperators);
8
20418
by: Stefano Sabatini | last post by:
Hi all, I'm encountering this while trying to implement a factory singleton method to generate objects. The singleton has a static map which binds a static creation function defined in each class to the type of the object to be created. Here it is the code, which is a modification of the wikipedia C++ factory example code: ----------------------------------8<--------------------------------
0
8851
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8754
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8542
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8630
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6181
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4343
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2760
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1740
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.