473,769 Members | 2,143 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

datarow update problem

I am getting an error on line 133. I am trying to update a datarow
using the find method, but it keeps throwing the error below:

int ItemKey = dv.Find(Item.in v_mast_uid);
DataRow dr;
if (ItemKey==-1) // NOT FOUND
{
dr = dt.NewRow();
dr["uid"] = Item.inv_mast_u id;
dr["rank"] = 1;
dr["item_id"] = Item.item_id;
dr["item_desc"] = Item.item_desc;
dr["extended_d esc"] = Item.extended_d esc;
dt.Rows.Add(dr) ;
}
else // IF FOUND
{
dr = dt.Rows.Find(It emKey);
dr["item_desc"] = "testing";

}

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.NullRefe renceException: Object reference not
set to an instance of an object.

Source Error:
Line 131:
Line 132: dr = dt.Rows.Find(It emKey);
Line 133: dr["item_desc"] = "testing";
Thank you

Jul 21 '05 #1
8 4132
Try this. I can not tell you why your find is failing, only that it is. Is
the DV and the DT variables related? Is the DV a dataview of the datatable?

else // IF FOUND
{

dr = dt.Rows.Find(It emKey);
if dr is nothing then
messagebox.show ("The find failed")
else
dr["item_desc"] = "testing";
end if
}

"Rodusa" <rc**********@y ahoo.com> wrote in message
news:11******** **************@ f14g2000cwb.goo glegroups.com.. .
I am getting an error on line 133. I am trying to update a datarow
using the find method, but it keeps throwing the error below:

int ItemKey = dv.Find(Item.in v_mast_uid);
DataRow dr;
if (ItemKey==-1) // NOT FOUND
{
dr = dt.NewRow();
dr["uid"] = Item.inv_mast_u id;
dr["rank"] = 1;
dr["item_id"] = Item.item_id;
dr["item_desc"] = Item.item_desc;
dr["extended_d esc"] = Item.extended_d esc;
dt.Rows.Add(dr) ;
}
else // IF FOUND
{
dr = dt.Rows.Find(It emKey);
dr["item_desc"] = "testing";

}

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.NullRefe renceException: Object reference not
set to an instance of an object.

Source Error:
Line 131:
Line 132: dr = dt.Rows.Find(It emKey);
Line 133: dr["item_desc"] = "testing";
Thank you

Jul 21 '05 #2
Yes.
I tried this first.
//DataView dv = new DataView(dt);
//dv.Sort = "uid";

Now I am using this code
DataView dv = new DataView(dt, "", "uid",
DataViewRowStat e.CurrentRows);
int ItemKey = dv.Find(Item.in v_mast_uid);

Jul 21 '05 #3
Chris,
thank you

I converted your VB code to this, but dr is always null. Is there any
relation between primary key of a Dataview and the primary key of
Datatable? Are they sincronized?

dr = dt.Rows.Find(It emKey);
if (dr!=null)
{
Response.Write( "Not Null");
}

Jul 21 '05 #4
Rodusa,

The find method finds the index that it has in the current dataview
situation, so why don't you update using the dataview.
\\\
dv.NewRow();
dv[key]["rank"] = 1;
///
or by using a datarowview from that row in the dataview.

I hope this helps?

Cor

"Rodusa" <rc**********@y ahoo.com>
....
I am getting an error on line 133. I am trying to update a datarow
using the find method, but it keeps throwing the error below:

int ItemKey = dv.Find(Item.in v_mast_uid);
DataRow dr;
if (ItemKey==-1) // NOT FOUND
{
dr = dt.NewRow();
dr["uid"] = Item.inv_mast_u id;
dr["rank"] = 1;
dr["item_id"] = Item.item_id;
dr["item_desc"] = Item.item_desc;
dr["extended_d esc"] = Item.extended_d esc;
dt.Rows.Add(dr) ;
}
else // IF FOUND
{
dr = dt.Rows.Find(It emKey);
dr["item_desc"] = "testing";

}

Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of
the current web request. Please review the stack trace for more
information about the error and where it originated in the code.

Exception Details: System.NullRefe renceException: Object reference not
set to an instance of an object.

Source Error:
Line 131:
Line 132: dr = dt.Rows.Find(It emKey);
Line 133: dr["item_desc"] = "testing";
Thank you

Jul 21 '05 #5
Cor,

Thank you very very much. Your suggestion seems to work. But now I am
confused. First I never thought that you could update a DataView. I
thought you had to update the DataTable and then create a DataView
instance.

In the modified code below I don't understand how the DataView is
maintaning the update value when I bind the results to a Datagrid. The
reason I ask this is because the Dataview is inside the foreach and is
being recreated for each loop (I know this is a waste of resources, but
I don't know any other way of doing it).
From my understanding, the changes in the DataView (for each loop)

should get overwritten, am I right? In addition, I still don't know why
the DatTable index is different of the index of a DataView? Was that
the cause of the problem before?

foreach(Common. InvmastContaine r Item in ArSearchedItems )
{
// CHECK DUPLICATES
// Adds found items to keywords datatable int ranking = 0;

DataView dv = new DataView(dt);
dv.Sort = "uid";
int ItemKey = dv.Find(Item.in v_mast_uid);

DataRow dr;
int m =ItemKey;
if (ItemKey==-1) // NOT FOUND
{
dr = dt.NewRow();
dr["uid"] = Item.inv_mast_u id;
dr["rank"] = 1;
dr["item_id"] = Item.item_id;
dr["item_desc"] = Item.item_desc;
dr["extended_d esc"] = Item.extended_d esc;
dt.Rows.Add(dr) ;
}
else // IF FOUND
{
dv[ItemKey]["rank"] = (int) (dv[ItemKey]["rank"]) +1;

}
}

}

DataView dvfinal = new DataView(dt);
dvfinal.Sort = "rank DESC";
DataGrid1.DataS ource= dvfinal;
DataGrid1.DataB ind();
Rod

Jul 21 '05 #6
Rodusa,

I did not know that it was about a webform solution with a datagrid.

However the dataview is a filter on your datatable, nothing more, one of its
important properties is the "DataTable" , which is nothing more than the
datatable that it supports. You can have as much dataviews you have and in
the datatable itself exists one as well with as property Defaultview.

When I see it right are you getting information back, make some updates
using that filter and create than a new dataview to show. In a windowform
situation is the last a waste of time, because the dataview is dynamic. In a
webform situation I never did this and would the winform solution not work.
Therefore when this works, do I know a nice solution as well now.

I hpe this helps?

Cor

"Rodusa" <rc**********@y ahoo.com>
Cor,

Thank you very very much. Your suggestion seems to work. But now I am
confused. First I never thought that you could update a DataView. I
thought you had to update the DataTable and then create a DataView
instance.

In the modified code below I don't understand how the DataView is
maintaning the update value when I bind the results to a Datagrid. The
reason I ask this is because the Dataview is inside the foreach and is
being recreated for each loop (I know this is a waste of resources, but
I don't know any other way of doing it).
From my understanding, the changes in the DataView (for each loop)

should get overwritten, am I right? In addition, I still don't know why
the DatTable index is different of the index of a DataView? Was that
the cause of the problem before?

foreach(Common. InvmastContaine r Item in ArSearchedItems )
{
// CHECK DUPLICATES
// Adds found items to keywords datatable int ranking = 0;

DataView dv = new DataView(dt);
dv.Sort = "uid";
int ItemKey = dv.Find(Item.in v_mast_uid);

DataRow dr;
int m =ItemKey;
if (ItemKey==-1) // NOT FOUND
{
dr = dt.NewRow();
dr["uid"] = Item.inv_mast_u id;
dr["rank"] = 1;
dr["item_id"] = Item.item_id;
dr["item_desc"] = Item.item_desc;
dr["extended_d esc"] = Item.extended_d esc;
dt.Rows.Add(dr) ;
}
else // IF FOUND
{
dv[ItemKey]["rank"] = (int) (dv[ItemKey]["rank"]) +1;

}
}

}

DataView dvfinal = new DataView(dt);
dvfinal.Sort = "rank DESC";
DataGrid1.DataS ource= dvfinal;
DataGrid1.DataB ind();
Rod

Jul 21 '05 #7
Cor, you saved my life. So, when you say that the dataview is just a
filter and I use this code
dv[ItemKey]["rank"] = (int) (dv[ItemKey]["rank"]) +1; does it update
automatically the datatable?

And when I use this code

DataView dv = new DataView(dt)
dv.Sort = "uid";

I am not copying all the schema and data to dv, just creating an index
according the sort param specified. If this is true, it seems to me
that the performance is degraded compared to updating the datatable,
because it has to reindex it for each loop while if you use the
datatable you can create final dataview and reindex just once.

In summary, can I say that this process is the same as updating a
Database index where any changes reflects in the Table?

Anyway, I did not understand your second paragraph. What did you want
to say?
Thank you

Rod

Jul 21 '05 #8
Rodusa,

I never say it does. I say it would do it in my opinion, you have to test it
yourself.

Because I do not understand what you want to do with your code this sample
beneath, when you say

DataView dv = new DataView(dt);

and nothing more, than (when there is no filter and no sort)

dv[0] [0] and dt.Rows[0][0] are referencing to the same object and therefore
will an setting of data in dv[0][0] be the same as too dt.Rows[0][0]

However you have to test it all yourself.

The second paragraph was to tell you the difference in a windowform and
webform situation, however test it first yourself before you go further,
that problem can that not be.

Cor

"Rodusa" <rc**********@y ahoo.com>
Cor, you saved my life. So, when you say that the dataview is just a
filter and I use this code
dv[ItemKey]["rank"] = (int) (dv[ItemKey]["rank"]) +1; does it update
automatically the datatable?

And when I use this code

DataView dv = new DataView(dt)
dv.Sort = "uid";

I am not copying all the schema and data to dv, just creating an index
according the sort param specified. If this is true, it seems to me
that the performance is degraded compared to updating the datatable,
because it has to reindex it for each loop while if you use the
datatable you can create final dataview and reindex just once.

In summary, can I say that this process is the same as updating a
Database index where any changes reflects in the Table?

Anyway, I did not understand your second paragraph. What did you want
to say?
Thank you

Rod

Jul 21 '05 #9

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

Similar topics

3
6995
by: Allan Bredahl | last post by:
Hi All I have a bit of a problem with using a datarow to store data that is show in a form. On form load I set the Value/Text properties of my form elements to the specific Column values of the DataRow which works just fine.
3
1771
by: Phil | last post by:
Hi, I have a client/server app. that uses a windows service for the server and asp.net web pages for the client side. My server class has 3 methods that Fill, Add a new record and Update a record. The Fill and Add routines work as expected but unfortunately the update request falls at the 1st hurdle. I pass two params to the remote(server) method for the update, one is the unique ID and the other is a string that is the name of the table...
3
21387
by: Jon S via DotNetMonster.com | last post by:
Hi all, I'm having a problem updating a simple change I've made to a Access 2000 table through databinding. The error I get is : An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll Additional information: Update requires a valid InsertCommand when passed DataRow collection with new rows.
4
2012
by: CaptRR | last post by:
I think this is the right group to post to, so here goes. My problem is this, I cannot update the datarow to save my life. Been on this for 2 days now, and still am no closer to figuring it out than I was before. I'm basicly taking date from some text boxes, trying to put them into a datarow and using that datarow to update the database, but its not working. The btn_update is where I am sending the information back to the addclient...
6
6006
by: Wanda | last post by:
Hello, I tried to update a row in a table by using the datarow and data adapter. Unfortunately, it doesn't update. I try finding that datarow and set it to "dr", I can see dr could be just an instance of the row, but aren't linked to the table. Is that why it doesn't update? If not, what is missing? Please help!!! Dim da As New SqlDataAdapter("select * from Table1", cn)
5
1407
by: rodchar | last post by:
Hey all, I thought what I was doing was pretty straightforward but apparently not. All I'm doing is loading a datarow, letting the user modify a field in the datarow by inputing into a textbox. I then take that textbox and assign the datarow field that value. But, as soon as the assignment occurs the datarow becomes nothing. And I have no idea why.
2
1587
by: Steve Amey | last post by:
Hi all I am binding a DataRow to some controls on a form. When I've finished editing the DataRow I click on a toolbar button to save the changes. If the focus is on a particular control, the item in the DataRow does not update to be the value of the control, for example, if I have a TextBox called txtEntry which is bound to the Entry column of the DataRow, if the focus remains on the TextBox while I click on the save button the...
8
565
by: Rodusa | last post by:
I am getting an error on line 133. I am trying to update a datarow using the find method, but it keeps throwing the error below: int ItemKey = dv.Find(Item.inv_mast_uid); DataRow dr; if (ItemKey==-1) // NOT FOUND { dr = dt.NewRow(); dr = Item.inv_mast_uid; dr = 1;
5
3111
by: rn5a | last post by:
The .NET 2.0 documentation states the following: When using a DataSet or DataTable in conjunction with a DataAdapter & a relational data source, use the Delete method of the DataRow to remove the row. The Delete method marks the row as Deleted in the DataSet or DataTable but does not remove it. Instead when the DataAdapter encounters a row marked as Deleted, it executes its DeleteCommand method to delete the row at the data source. The...
0
9579
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9422
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10038
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
9987
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
8867
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5294
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3952
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
3558
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2812
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.