473,320 Members | 1,804 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,320 software developers and data experts.

get data from datagridview

hello,

i am new to c#.net.

i have imported data in datagridview form ms access database.

now i want to store each row of datagridview saperatly in string array

so in saperate class i have created string array named dirurl

my code is as follows

IN CLASS1

code:

public static string[] dirurl = new string[100];

and in my form i want to get as follows ::

int tin = dataGridView1.RowCount;

for (int j=0; j <= tin; j++)
{
Class1.dirurl[j] = dataGridView1.Rows[j].Cells[1].Value.ToString();

}

but when program goes to execute for loop it gives me following error:

Object reference not set to an instance of an object.

please help me to get data in dirurl array...
Jul 12 '08 #1
4 2861
kenobewan
4,871 Expert 4TB
Not sure why you want to declare your string in a class and call it from the form? Suggest debug. Does Class1.dirurl[j] have a value for any instances of j?
Jul 12 '08 #2
Not sure why you want to declare your string in a class and call it from the form? Suggest debug. Does Class1.dirurl[j] have a value for any instances of j?


actually i declared dirurl array in class for SIMPLICITY so that i can get data of it by any form in my application .

No,class1.dirurl[j] has not any value for any instance of j.but i want to assign it by for loop as mentioned earlier .

I want to know why the error comes like

"Object reference not set to an instance of an object."

OR

alternatively can you give me an idea by which i can get data from datagridview1 and store in string array for further manipulation..
Jul 12 '08 #3
kenobewan
4,871 Expert 4TB
Here is an exmple:
Expand|Select|Wrap|Line Numbers
  1. System.Collections.ArrayList array = new System.Collections.ArrayList();
  2. for (int i = 0; i < this.dataGridView1.Columns.Count; i++)
  3. array.Add(this.dataGridView1[i, 0].Value); /// Make sure the second
  4. value is a valid row
  5.  
Jul 13 '08 #4
Here is an exmple:
Expand|Select|Wrap|Line Numbers
  1. System.Collections.ArrayList array = new System.Collections.ArrayList();
  2. for (int i = 0; i < this.dataGridView1.Columns.Count; i++)
  3. array.Add(this.dataGridView1[i, 0].Value); /// Make sure the second
  4. value is a valid row
  5.  



thanks a lot .

it is working now....

thanks again.
Jul 13 '08 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Andy | last post by:
I have a C# application that is using a DataGridView (DGV). The DGV uses a table adapter to connect to the datasource, which uses a DataSet as the data. The DataSet has some constraints placed on...
2
by: Ivan | last post by:
I have a class Foo which have two property. I have a thread that do some process and update class Foo int B. I have a datagridview on main form. this datagridview data source to this class Foo and...
2
by: Rick Shaw | last post by:
Hi, I have a problem with the datagridview not refreshed when the application first appear on the screen. The datagridview display data from a table in the dataset. At the same time, I've added...
6
by: alexia.bee | last post by:
Hi all, I am new to C# so please bear me :). I have an app which uses datagridview. it has 8 columns. I also have struct which has 8 members(the same as the datagridview). when I add row to...
0
by: David Mayerovitch | last post by:
As an exercise in learning Visual Basic 2005, I am putting together a simple XML editor. I place on the form the objects DataGridView1 and DataSet1. ' Read an XML file into DataSet1:...
9
by: trint | last post by:
How can I retrieve all of the data from a datagridview? Any help is appreciated. Thanks, Trint
6
by: =?Utf-8?B?TWFyY2Vsbw==?= | last post by:
Hello, I am new to pulling data into VB and using DataGridViews..... so this might be a dumb question but I can not seem to understand how to make this work. What I need acomplished: Exec a...
4
by: =?Utf-8?B?UmludSBHb3BhbGFrcmlzaG5hIFBpbGxhaQ==?= | last post by:
Hi All, I have an application that fetch data thru a store proc and display in a datagrid, but after successful execution of proc the data grid is not visible.Please go thru the following code...
2
by: hjin | last post by:
DataGridView takes very much time if I update a lot of data I have a DataGridView which has a DataSource (a DataTable) of 3000 rows. If I want to update one column of every rows in the DataTable,...
1
by: Limno | last post by:
Can anyone suggest me how to pass datagridview data to database. Process must be like this, if the user enter multiple data into the datagridview after user press "save" button, datagridview data...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
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...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
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 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.