473,385 Members | 1,890 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,385 software developers and data experts.

Unable to update a MSSql schema programatically in .NET 3.5SP1

1
Hello,

I have been struggling trying to update the schema of a database. All I am trying to do is set the primary key of a table. However, I will set the column, but it does not set it. When I open the DB in the viewer the PK has not been set. I am using the following code. Is there a special way I need to send the update sice I'm dealing with the schema and not just data? I am developing in VS 2008/Win7 x64 Ultimate/.Net 3.5 SP1/C# -- The database is MS Sql (*.mdf) 2005.

I ran a few tests and I am able to add rows to my table successfully, so I am wondering, coudl there possibly be something with my connection string that is preventing me from updating the schema?

string strCon = @"Data Source=.\SQLEXPRESS;AttachDbFilename=""" + DBPathAndName + @""";Integrated Security=True;Connect Timeout=30;User Instance=True";

DataTable table = new DataTable();

SqlDataAdapter dataAdapter = new SqlDataAdapter("SELECT * FROM ROOM", strCon);

SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);

table.Locale = System.Globalization.CultureInfo.InvariantCulture;

dataAdapter.FillSchema(table, SchemaType.Source);
dataAdapter.Fill(table);

try
{
DataColumn[] cols = { table.Columns["ROOM_ID"] };
table.PrimaryKey = cols;

dataAdapter.Update(table);

dataAdapter.Dispose();
commandBuilder.Dispose();
}
catch(Exception ex)
{
Console.WriteLine(ex.ToString());
}
Sep 4 '10 #1
0 965

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Alberto | last post by:
Hello all, I'm new in this newsgroup and I apologise if my question has already done. Let me knwo if FAQ is avaible somewhere. I use msSQL server to manage data for a B2B portal. Orginal data...
1
by: Duncan Smith | last post by:
Hello All, Has anyone found a way to specify an xsd schema programatically when using the apache xerces xml processor? I know that the validation works fine as long as the xml instance document...
2
by: M Rao | last post by:
I have xml data coming in as a stream from a web service running against exchange server.The attributes for the elements dtstart and dtend, b:dt="dateTime.tz"...
0
by: Michael | last post by:
Hi everyone, I would like to know how to update the Schema without VS going crazy. Say I generated a dataset using the SQLDataAdapter, now I make a change to the stored proc, and there are a few...
2
by: Nathan Wiegman | last post by:
Hi, I am using the XSD utility to generate schemas for some of the classes that we serialize in our project. Everything works fine and dandy until I try and create a schema for a class that...
8
by: WideBoy | last post by:
Hi All, I'm looking for a little example of an xml document which is validated using an inline xml schema. I'm a bit of a newbie, and I'm finding this to be a bit of a mind bender, so an...
0
by: Anbu.Thangarathinam | last post by:
Hi All, I'm looking for a help on stub generation form wsdl files using wsdl.exe supplied by visual studio 2005. My probelm is exactly similar to the query posted in...
1
by: leno | last post by:
Hi all, I'm having this problem when i combined multiple schema's into one. The error msg is below: Unable to load schema with target namespace 'http://www.tdbanknorth.com/IFX170_TDBN' from...
1
by: shajeela | last post by:
1.I create a datagridview control 2.connected using a oledb adapter 3.problem is if i run the program the old value is displayed 4.for viewing the old value i have to close the current window,and...
1
by: helplakshmi | last post by:
Hi All, I wish you a Happy new year!!!.. My requirement is to upload an excel file using PHP and to update the data in MSSQL. For which i have designed a screen so that the user can browse 2...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.