473,320 Members | 1,991 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.

Dataset: NullReferenceException problem

Hi

Can anybody help? (ASP.NET 1.1)

The event below is triggered when the user clicks an update button
column.

I am trying to update a dataset which eventually gets bound with a
datagrid, with values from that same datagrid.
Note there is no SQL code here, all the dataset data is coming from the
viewstate.

This seems to work fine, OK it's hardly efficient, and yes I should
probably be using a session variable instead.

Back to the dataset problem:

This is the offending line:
rowUpdate.CurrencyID = strCurrency

This is the error message:
[NullReferenceException: Object reference not set to an instance of an
object.]

Note if I take out the line with the error, my datagrid will be
displayed, no problems, it just won't show the updated value. So
everything appears well until I do the update.

I've spend a day looking at this and frankly I'm completely stuck!
Code is below.

Many thanks for you help!

Alex

'------------------------------------------------------------------

Private Sub MyDataGrid_Update(ByVal source As System.Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs ) Handles
MyDataGrid.UpdateCommand

'Gets a value from a drop down list in my datagrid
Dim strCurrency As String = CType(e.Item.Cells(10).Controls(1),
DropDownList).SelectedValue
Response.Write(strCurrency) 'Yep definately got the value

Dim datasetsaved As MyDataset

'Gets dataset data previously saved from viewstate, not efficient but
works
datasetsaved = CType(viewstate.Item("Datagriddata"), MyDataset)
Response.Write("ROW TO EDIT = " & ViewState("ProductInvoiceID")) '
Shows the right row I just edited in a datagrid - definately works

Dim rowUpdate As MyDataset.MyDataTableRow =
MyDataset1.MyDataTable.FindByProductInvoiceID(View State("ProductInvoiceID"))
'No errors so far

rowUpdate.CurrencyID = strCurrency 'ERROR MESSAGE TRIGGERED HERE!!!

'Saved updated dataset back to the viewstate for a later time
viewstate.Remove("Datagriddata")
viewstate.Add("Datagriddata", datasetsaved)

'Populate and bind the datagrid
MyDataGrid.DataSource = datasetsaved.MyDataTable
MyDataGrid.databind

'Set datagrid to non editable
MyDataGrid.EditItemIndex = -1

End Sub
'------------------------------------------------------------------
FIN

Nov 19 '05 #1
3 1154
I would guess that rowUpdate is null, and that the line before your
error is not finding the MyDataTableRow you are looking for. Try a
if(rowUpdate != null) check before the line that is erroring, and see
if that is the problem.

Nov 19 '05 #2
It would appear that FindByProductInvoiceID is not returning a row to
update. This leaves rowUpdate as a null (Nothing) reference - it
doesn't point to an an object, and so there is no CurrencyID property
to store data into.

Could you step through the method with the debugger and see why it
might not be finding a record?

--
Scott
http://www.OdeToCode.com/blogs/scott/

On 6 May 2005 07:42:16 -0700, po******@alexshirley.com wrote:
Hi

Can anybody help? (ASP.NET 1.1)

The event below is triggered when the user clicks an update button
column.

I am trying to update a dataset which eventually gets bound with a
datagrid, with values from that same datagrid.
Note there is no SQL code here, all the dataset data is coming from the
viewstate.

This seems to work fine, OK it's hardly efficient, and yes I should
probably be using a session variable instead.

Back to the dataset problem:

This is the offending line:
rowUpdate.CurrencyID = strCurrency

This is the error message:
[NullReferenceException: Object reference not set to an instance of an
object.]

Note if I take out the line with the error, my datagrid will be
displayed, no problems, it just won't show the updated value. So
everything appears well until I do the update.

I've spend a day looking at this and frankly I'm completely stuck!
Code is below.

Many thanks for you help!

Alex

'------------------------------------------------------------------

Private Sub MyDataGrid_Update(ByVal source As System.Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArg s) Handles
MyDataGrid.UpdateCommand

'Gets a value from a drop down list in my datagrid
Dim strCurrency As String = CType(e.Item.Cells(10).Controls(1),
DropDownList).SelectedValue
Response.Write(strCurrency) 'Yep definately got the value

Dim datasetsaved As MyDataset

'Gets dataset data previously saved from viewstate, not efficient but
works
datasetsaved = CType(viewstate.Item("Datagriddata"), MyDataset)
Response.Write("ROW TO EDIT = " & ViewState("ProductInvoiceID")) '
Shows the right row I just edited in a datagrid - definately works

Dim rowUpdate As MyDataset.MyDataTableRow =
MyDataset1.MyDataTable.FindByProductInvoiceID(Vie wState("ProductInvoiceID"))
'No errors so far

rowUpdate.CurrencyID = strCurrency 'ERROR MESSAGE TRIGGERED HERE!!!

'Saved updated dataset back to the viewstate for a later time
viewstate.Remove("Datagriddata")
viewstate.Add("Datagriddata", datasetsaved)

'Populate and bind the datagrid
MyDataGrid.DataSource = datasetsaved.MyDataTable
MyDataGrid.databind

'Set datagrid to non editable
MyDataGrid.EditItemIndex = -1

End Sub
'------------------------------------------------------------------
FIN


Nov 19 '05 #3
Sorry I was being incredibly thick:

MyDataset1.MyDataTable.FindByP*roductInvoiceID(Vie wState("Pro*ductInvoiceID"))
Should be:

MyDataset1.datasetsaved.FindByP*roductInvoiceID(Vi ewState("Pro*ductInvoiceID"))
I was looking up the row wrong dataset (Doh!). The one without the
viewstate populated.
Sometime you look so hard you just can't see the obvious (and you write
off a day!)

Many thanks

Alex

Nov 19 '05 #4

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

Similar topics

6
by: Programatix | last post by:
Hi, I'm working on a project which includes WebServices and Windows Form application. The Windows Form application will call the WebServices to retrieve data from database. The data will be...
2
by: James Ankrom | last post by:
Why does this fail? Dim relResources As New Data.DataRelation("Application_Resources", ..Tables("User_Applications").Columns("Application_id"),...
4
by: Eric | last post by:
Hi, can anyone guide me throught this: In my application, I have a global DataSet. I then run FTP processes in up to 10 simultaneous threads and each thread calls progress events in the main...
0
by: Steve | last post by:
I have a dataset. I fill it with two recordsets from SQL queries. Tables are called tblPlanFYSpendingStage, tblSpendingStage.
12
by: Bishoy George | last post by:
I have a dataset called ds1 filled with 2 tables Employees and Customers from Northwind database. I have dropdownList called ddLastName with the following properties: ddLastName.DataSource =...
0
by: Derek Vincent | last post by:
Why am I having problems filling my dataset when I select fields of type varchar(350) from interbase? I can fill the dataset when I select every other field in the table but I receive and error...
2
by: eljainc | last post by:
Hello, I'm pretty new to C# programming, so be gentle with me. I have a block of code which is the following: scheduleDomainController1.ConnectionString = "data source=.\\SQLEXPRESS;"+...
2
by: Carl Heller | last post by:
Working in VS2003, .Net 1.1 I'm working on a project where I compare data between two databases. This is a lengthy process, and very data intensive, so I decided to create a class, and thread...
12
by: Andy B | last post by:
I need to custom build and use a dataset in c# to use with xml. Does anybody know where I can find out how to do something like this? I was going to create a class that generated the dataset and...
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
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: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
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.