I have an ASP.NET/VB app that updates values in a DataTable over the
course of about 3 different pages. On the way out of the first of
these pages, I explicitly build the DataTable from values in a
DataGrid, and set the PrimaryKey of the DataTable to be the first cell
in the grid (which is a UserID value). I then store the DataTable in
a session object, from which it is retrieved for subsequent pages.
All this seems to be working fine.
On the second page, I retrieve the DataTable from the session object,
apply a filter to it, and display the filtered data in a DataGrid. In
this grid, the user can change the data, specifically assigning an
employee to a different supervisor. The Grid is populated with the
current employee/supervisor assignment in the database, and then any
necessary changes are made by the user. This, too, seems to be
working fine.
The problem I'm having is that on the update command of the Grid,
which is where I'm updating the DataTable (the thought being that I
would just do an "in-place" update of the DataTable and then rebind
the grid). I am able to trap the new assignment values (which are set
in a listbox within the grid) and can trap the employee ID value from
the grid (which is my primary key), but whenever I call the
LoadDataRow method, rather than updating the row based on the primary
key, a new row insert is *attempted*. I say attempted because I get
an error on the EndLoadData method, which I believe is due to not
passing in values for all the columns.
I was hoping to be able to just pass in the key value and the values
of the columns that had changed, but apparently that is not
sufficient. Which is the first question - when attempting a
LoadDataRow call, do I need to pass in valid values for *all* of the
columns in the datatable (except, of course, those for which there are
default values, of which I have none in this instance). You'll see in
my example code that I'm just passing in the first, eighth and ninth
columns, which I suspect is the problem.
However, the *real* question is why isn't the LoadDataRow method
finding the pre-existence of the key value in the table? I've checked
and the value returned by my code is exactly the same as the one in
the table, length is the same, etc. I set the primary key when I
first build the table on the previous page, but I thought perhaps that
attribute somehow gets lots when I set the DataTable to a session
object so, as you will see in the example, I explicitly set the
primary key again on this page, which seems to work, but the code
still inserts a new row (or attempts to).
Here is the relevant code from the page in question:
Dim DDL As DropDownList = CType(e.Item.Ce lls(2).Controls (1),
DropDownList)
Dim NewID As Integer = DDL.SelectedInd ex
Dim SupervisorID As String = DDL.Items(NewID ).Value
Dim SupervisorName As String = DDL.Items(NewID ).Text
Dim NewRow(9) As Object
Dim Key As TextBox = e.Item.Cells(1) .Controls(0)
Dim RowID As String = Key.Text
Dim dsTechnicianLis t As DataTable
dsTechnicianLis t =
CType(HttpConte xt.Current.Sess ion("ILApplicat ors"),
System.Data.Dat aTable)
Dim dcFirst As DataColumn = dsTechnicianLis t.Columns(0)
Dim dcPrimary(1) As DataColumn
dcPrimary(0) = dcFirst
dsTechnicianLis t.PrimaryKey = dcPrimary
NewRow(0) = RowID
NewRow(7) = SupervisorName
NewRow(8) = SupervisorID
Dim myRow As DataRow
dsTechnicianLis t.BeginLoadData ()
myRow = dsTechnicianLis t.LoadDataRow(N ewRow, True)
dsTechnicianLis t.EndLoadData()
Any help or ideas would be GREATLY appreciated!
TIA,
Mike 1 4384
I found the answer to my own problem. Although it is not documented
you must call the AcceptChanges method *before* calling the
LoadDataRow method. This really doesn't make sense, as passing in
True for the fAcceptChanges argument of LoadDataRow forces it to be
called in conjunction with LoadDataRow.
At any rate, I added AcceptChanges just before LoadDataRow and all is
well!
On Thu, 04 Dec 2003 19:22:46 GMT, Mike
<ga_harley_guy@ _REMOVE_yahoo.c om> wrote: I have an ASP.NET/VB app that updates values in a DataTable over the course of about 3 different pages. On the way out of the first of these pages, I explicitly build the DataTable from values in a DataGrid, and set the PrimaryKey of the DataTable to be the first cell in the grid (which is a UserID value). I then store the DataTable in a session object, from which it is retrieved for subsequent pages. All this seems to be working fine.
On the second page, I retrieve the DataTable from the session object, apply a filter to it, and display the filtered data in a DataGrid. In this grid, the user can change the data, specifically assigning an employee to a different supervisor. The Grid is populated with the current employee/supervisor assignment in the database, and then any necessary changes are made by the user. This, too, seems to be working fine.
The problem I'm having is that on the update command of the Grid, which is where I'm updating the DataTable (the thought being that I would just do an "in-place" update of the DataTable and then rebind the grid). I am able to trap the new assignment values (which are set in a listbox within the grid) and can trap the employee ID value from the grid (which is my primary key), but whenever I call the LoadDataRow method, rather than updating the row based on the primary key, a new row insert is *attempted*. I say attempted because I get an error on the EndLoadData method, which I believe is due to not passing in values for all the columns.
I was hoping to be able to just pass in the key value and the values of the columns that had changed, but apparently that is not sufficient. Which is the first question - when attempting a LoadDataRow call, do I need to pass in valid values for *all* of the columns in the datatable (except, of course, those for which there are default values, of which I have none in this instance). You'll see in my example code that I'm just passing in the first, eighth and ninth columns, which I suspect is the problem.
However, the *real* question is why isn't the LoadDataRow method finding the pre-existence of the key value in the table? I've checked and the value returned by my code is exactly the same as the one in the table, length is the same, etc. I set the primary key when I first build the table on the previous page, but I thought perhaps that attribute somehow gets lots when I set the DataTable to a session object so, as you will see in the example, I explicitly set the primary key again on this page, which seems to work, but the code still inserts a new row (or attempts to).
Here is the relevant code from the page in question:
Dim DDL As DropDownList = CType(e.Item.Ce lls(2).Controls (1), DropDownList ) Dim NewID As Integer = DDL.SelectedInd ex Dim SupervisorID As String = DDL.Items(NewID ).Value Dim SupervisorName As String = DDL.Items(NewID ).Text Dim NewRow(9) As Object Dim Key As TextBox = e.Item.Cells(1) .Controls(0) Dim RowID As String = Key.Text
Dim dsTechnicianLis t As DataTable dsTechnicianLis t = CType(HttpCont ext.Current.Ses sion("ILApplica tors"), System.Data.Da taTable) Dim dcFirst As DataColumn = dsTechnicianLis t.Columns(0) Dim dcPrimary(1) As DataColumn dcPrimary(0) = dcFirst dsTechnicianLis t.PrimaryKey = dcPrimary
NewRow(0) = RowID NewRow(7) = SupervisorName NewRow(8) = SupervisorID Dim myRow As DataRow dsTechnicianLis t.BeginLoadData () myRow = dsTechnicianLis t.LoadDataRow(N ewRow, True) dsTechnicianLis t.EndLoadData()
Any help or ideas would be GREATLY appreciated!
TIA, Mike This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Bill Toulias |
last post by:
I want to be able to display the tuples of a select query (which may change
at runtime, so no prior knowledge for column characteristics) and edit them
as well.
I used this code, that executes the select, gets schema from the datareader,
creates a table that can host data of that type, fills it with data from the
datareader and then binds it to a DataGrid.
The problem is that although i seem to do everything correctly and although
all...
|
by: Mike |
last post by:
I have an ASP.NET/VB app that updates values in a DataTable over the
course of about 3 different pages. On the way out of the first of
these pages, I explicitly build the DataTable from values in a
DataGrid, and set the PrimaryKey of the DataTable to be the first cell
in the grid (which is a UserID value). I then store the DataTable in
a session object, from which it is retrieved for subsequent pages.
All this seems to be working fine.
...
|
by: Danny Ni |
last post by:
Hi,
If I want to programatically add rows to a DataTable, do I call
AcceptChanges per row? Or do I call AcceptChanges after all rows added?
TIA
|
by: Flack |
last post by:
I have pasted at the end of this message a small sample program I whipped up
to do some testing.
It's a form with a datagrid and two buttons. Each button clears the
dataTable that is the source of the dataGrid, and then adds five rows.
Button2 is the same as button1 just that it does this in a different thread
(I was testing if I was having some threading issues).
Anyway, it seems that the location of the call to dt.Rows.Clear()...
|
by: cindy |
last post by:
this is the call
private void Page_Load(object sender, System.EventArgs e)
{
OdbcConnection connection = new OdbcConnection ("DSN=PFW52");
CreateDataAdapter(connection);
}
this is the code, no errors, but NO UPDATE I have to use ODBC I just
need to update a field based on a key, EMBARASSED to say days going
| |
by: Tim Cowan |
last post by:
Hi,
I was wondering if there is a quicker way to do this? I have a select all
check box for data in a grid and when checked I want the checkboxes in the
grid to be checked.
I am currently using:
foreach(DataRowView DRV in dvData)
{
|
by: George |
last post by:
Got a question about the side effect of DataAdapter.Update() and
DataTable.GetChanges().
Say I set up a DataTable and a DataAdapter in a class. Delete (Not remove)
a row in the data table and call the following method.
public void JobListDataTableFromAccessCommitChange()
{
System.Data.DataTable oChangeDataTable;
|
by: John Cosmas |
last post by:
I have a DATATABLE which I have populated in my application, and I need it
written out to a particular table I specify in my ACCESS database. My code
works to the point of the MERGE and UPDATE, but it creates exactly the
number of BLANK records per the populated DATATABLE. Here is my code...
pstrDestinationTable = "tws_tbl_Case_Scanner_" &
GetDateTimeStamp()
pstrSQL = "SELECT * INTO " & pstrDestinationTable & " FROM...
|
by: inpuarg |
last post by:
I have 2 datatables. They are identical. I want to compare them by
cell's content. They are all same.
But dt1 == dt2 or
dt1.GetHashCode() == dt2.GetHashCode() doesn 't work.
There are big amount of rows in theese datatables . So i don 't want
to enumerate each rows. This is not efficient and unacceptable for my
current application.
|
by: joaotsetsemoita |
last post by:
Hello everyone,
im completly new to vb.net and I was assigned to do a simple piece of
software that just had to select from um db in a MS access data base
and insert into a SQL server Database. The structure tables are
exactly the same so there's no need in data conversation.
My idea was to fill a datatable with the results from my
oledbdataadapter and then use that dataset to update on my
sqldataadapterm, however I cant find the way...
|
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...
| |
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...
|
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...
|
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...
|
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();...
|
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...
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
|
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...
| |