Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET 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 January 22nd, 2004, 09:31 AM
Authorized User
 
Join Date: Jan 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default Adding constraints to the datasource

Hi,

I have a table which doesnt have a primary key. Now I created a dtaset by querying this table. Now I added a primary constraint to this Datasets Datatable. Now I want to update my table using commandbuilder. Is there anyway I can write my added constraint also to the datasource ?


 
Old January 22nd, 2004, 10:08 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

if u r using DataAdapter i dont think that it'll couse a problem! does it?! can u tell more.

Always:),
Hovik Melkomian.
 
Old January 23rd, 2004, 05:08 AM
Authorized User
 
Join Date: Jan 2004
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I am using a dataadapter only. In the datatable the constraints are there. But Update command only inserts data. Not the constraints. Should I do anything else to make it work ?

// there is no rows in the table now.
SqlDataAdapter adapter = new SqlAdapter("SELECT * FROM EMPLOYEES", connection);
DataSet dataSet = new DataSet("Employees");
adapter.Fill(dataSet);
SqlCommandBuilder builder = new SqlCommandBuilder(adapter);
DataRow newrow = dataSet.Tables[0].NewRow;
// filling the new row with values...
...
..
DataColumn[] primaryKey = {dataSet.Tables[0].Coulmn[0]};
dataSet.Tables[0].PrimaryKey = primaryKey;
adapter.Update(dataSet);

---Row is inserted..but no primary key...











 
Old January 24th, 2004, 03:43 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 996
Thanks: 2
Thanked 11 Times in 11 Posts
Send a message via Yahoo to melvik
Default

If want to [u]update ur Primary field </u>in table, ur problem is in DataBase not in ur code. Make sure ur primary field is set toIDENTITY.
keep in touch.

Always:),
Hovik Melkomian.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Dropping constraints epp_b MySQL 2 September 12th, 2006 09:22 PM
How do you suspend constraints? Aaron Edwards SQL Server 2005 2 July 31st, 2006 12:16 PM
Object datasource VS DataSource SoftMind BOOK: ASP.NET 2.0 Instant Results ISBN: 978-0-471-74951-6 4 July 27th, 2006 10:44 PM
Rules/Constraints dhay1999 SQL Server 2000 1 July 11th, 2004 01:50 PM
Tricks with Constraints ebsutherla SQL Server 2000 3 June 6th, 2004 05:28 AM





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