开发者

what changes should i do, after altering columns in sql Database?

hii

its the first time i use database in c#. i am trying to add database to visual studio c# ,, read data and save data to the database.

so i have created a database and a table inside it called "Users". then i connect the windows forms to the database.

after that it worked fine in retrieving data ( query: all users) but after i have edited a column type from dateTim开发者_C百科e to int,, it gives me an exception " Constraints Exception was unhandled at the following line

this.usersTableAdapter.Fill(this.smartHomeDataSet.Users);

and the form dosent load at all. !!

so i guess there is something i have to do , after the changes i have made to the database table, so it can be applied to my application.

it might be something easy and obvious, but forgive me its my first time in database.

thanks for your help, All.

edit:

what i did, is editing the column (date of birth) in the table definition

it was: dateTime - not allowNull

changed to : int - allowNull


You do not need to regenerage the dataset. Follow the steps to update your dataset.

1.) Goto Typed DataSet designer. Right click the TableAdapter header and select Configure option. This will launch the Table Adapter configuration wizard.

2.) Normally complete the Wizard and update the fields in the Query Designer step. This is where it will add the new coloumns and remove the coloumns not found in the resultset of the query.

3.) After completing the wizard you'll quickly observe that the new fields have been added into the Corresponding DataTable. This will also ensure the result set of all TableAdapter methods is also updated and you do not need to change each method individually. we have done this many times, and it always works without fail.

4.) Only thing you need to do manually is removal of the coloumns from DataTable, in case if you have removed field from the query. The wizard will update and add the coloumns but it will not remove the coloumns from the DataTable. Simply,just go ahead and delete the coloumn from the DataTable.

You're done.


Well I guess you've already changed the datatype of the column in dataset.

But the exception may be due to getting null values into the datatable column which has AllowNull set to false. Did you change the nullable property of the column in db? If so, change the AllowNull too.


It looks like you are using strongly typed datasets and table adapters. If this is the case, you need to regenerate the datasets (or alter them manually) if you make changes to the database columns.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜