Wrox Programmer Forums
|
ASP.NET 1.x and 2.0 Application Design Application design with ASP.NET 1.0, 1.1, and 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 1.x and 2.0 Application Design section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 26th, 2003, 04:35 PM
Authorized User
 
Join Date: Aug 2003
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default updating database

I am trying to do an update on the database using sqldataadapter.update method. I build my own datatable that I need to update the database with. Here is a part of the code:

Dim dt As New DataTable()
Dim ds As New DataSet()
Dim dr As DataRow

Dim keys(2) As DataColumn
Dim col1 As New DataColumn("LMC", GetType(String))
Dim col2 As New DataColumn("UserID", GetType(Short))
keys(0) = col1
keys(1) = col2

dt.Columns.Add(col1)
dt.Columns.Add(col2)

dt.PrimaryKey = keys

dr = dt.NewRow()
dr("UserID") = CType(12, Short)
dr("LMC") = New String("2111150029284")

dt.Rows.Add(dr)
ds.Tables.Add(dt)

I use a dataservice layer blackbox which makes the sqlconnection and gets the selectcommand from an XML file. It doens't explicitly build any updatecommand, but I know that update should still work, because the same dataservice layer update works for another page.

When I try to do an update for this page, sqldataadapter.update fails in the dataservice layer, and I can't figure out why.

All the working examples of update I have seen, have to do with a dataset that has been changed and then used for update, as opposed to create a new one on the fly like I'm doing. I wonder if that might have anything to do with it. What about the acceptchanges method of dataset? Might that have some effect?

I know this is not very specific, but I wonder if anyone might have some ideas to explore. I have tried doing this with and without the primary key.

I will appreciate any help.

Thanks
 
Old September 1st, 2004, 05:42 AM
Registered User
 
Join Date: Sep 2004
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I have the same problem.
If you found any solution

I will appreciate any help.

Thanks, eitan shapir

Quote:
quote:Originally posted by texasraven
 I am trying to do an update on the database using sqldataadapter.update method. I build my own datatable that I need to update the database with. Here is a part of the code:

Dim dt As New DataTable()
Dim ds As New DataSet()
Dim dr As DataRow

Dim keys(2) As DataColumn
Dim col1 As New DataColumn("LMC", GetType(String))
Dim col2 As New DataColumn("UserID", GetType(Short))
keys(0) = col1
keys(1) = col2

dt.Columns.Add(col1)
dt.Columns.Add(col2)

dt.PrimaryKey = keys

dr = dt.NewRow()
dr("UserID") = CType(12, Short)
dr("LMC") = New String("2111150029284")

dt.Rows.Add(dr)
ds.Tables.Add(dt)

I use a dataservice layer blackbox which makes the sqlconnection and gets the selectcommand from an XML file. It doens't explicitly build any updatecommand, but I know that update should still work, because the same dataservice layer update works for another page.

When I try to do an update for this page, sqldataadapter.update fails in the dataservice layer, and I can't figure out why.

All the working examples of update I have seen, have to do with a dataset that has been changed and then used for update, as opposed to create a new one on the fly like I'm doing. I wonder if that might have anything to do with it. What about the acceptchanges method of dataset? Might that have some effect?

I know this is not very specific, but I wonder if anyone might have some ideas to explore. I have tried doing this with and without the primary key.

I will appreciate any help.

Thanks

 
Old September 21st, 2004, 05:14 PM
Authorized User
 
Join Date: Aug 2003
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It does have to do with the fact that the dataset is new. Since the dataset does not have the metadata of the sql table, it doesn't know how to call the updates.

I'm sure you can do this by somehow retrieving the sql table schema and updating the dataset metadata. That would be the elegant solution, but I'm afraid I don't know how.

Another, perhaps less elegant solution is to do this.

Retrieve a dataset by querying the datatable that you want to update. You can even use a query that returns nothing, such as
SELECT * FROM TABLEIWANTTOUPDATE WHERE 1 = 2.

If you make changes to this dataset and call the update, the update will work since the dataset will now have the schema of the sql table, and it will know how to call updates on the table.

HTH,

texasraven






Similar Threads
Thread Thread Starter Forum Replies Last Post
updating database musicradiolive Classic ASP Databases 1 August 17th, 2006 12:23 AM
database not updating ellie BOOK: Beginning ASP 3.0 1 April 16th, 2006 05:28 AM
Help for Updating the database bspradeep Classic ASP Databases 1 May 10th, 2005 03:13 AM
Updating a database Gary_M Classic ASP Databases 4 November 7th, 2003 11:03 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.