|
dear all i am a new bie and have following problem in developing a windows accounts application: a. I created a data adopter and a data set through wizard at design time. b. I changed the "default attribute" of xsd file of one database field manually at design time. This default attribute appears on a form whenever user adds new data (addnew method in vb.net) Now during the course of running the application user wants to have capability to change the default attribute and wants to allot new value.,so that whenver new data is entered the new default value should appear. How to go about this | | Farhan Iqbal Monday, August 17, 2009 7:51 AM | Hi! You do not want to change the XSD file at runtime... You probably just want to change the default value of a DataColumn. If you are using an XSD, this means that you use ADO.Net and a DataSet Or a DataTable. A DataColumn is a property of a Datatable. Use the next line of code to programmatically change the default value for a DataColumn. myDataTable.Columns["Date"].DefaultValue = myNewDefaultValue
Please click 'Mark as Answer' on the post that helped you.- Marked As Answer byAland LiMSFT, ModeratorMonday, August 24, 2009 2:21 AM
- Edited byDamPee Monday, August 17, 2009 12:15 PMlayout change
-
| | DamPee Monday, August 17, 2009 12:14 PM | Farhan, I am bothered by this thread for two reasons.
1) You say that you only have a DataSet, but no DataTable. A DataSet is pretty useless without any DataTables, so I'm not sure what's up with that, or what you actually have versus what you think you have. You should take DamPee's advice about how to alter the DefaultValue in the DataTable, because that advice was totally correct!!
2) Aland's advice, which Aland marked as an answer (which, I don't agree with BTW ... marking one's own post as an answer strikes me as being a bit egotistical and I would unmark it if I could) is very flawed. You do NOT want to mess with the auto-generated stuff, because, as noted, you have to alter it again any time you re-gen your DataSet. This is a BAD, BAD, BAD answer!! Please un-mark it!!! ~~Bonnie Berent [C# MVP]- Marked As Answer byFarhan Iqbal Thursday, August 27, 2009 7:10 AM
-
| | BonnieB Sunday, August 23, 2009 4:10 PM | Hi! You do not want to change the XSD file at runtime... You probably just want to change the default value of a DataColumn. If you are using an XSD, this means that you use ADO.Net and a DataSet Or a DataTable. A DataColumn is a property of a Datatable. Use the next line of code to programmatically change the default value for a DataColumn. myDataTable.Columns["Date"].DefaultValue = myNewDefaultValue
Please click 'Mark as Answer' on the post that helped you.- Marked As Answer byAland LiMSFT, ModeratorMonday, August 24, 2009 2:21 AM
- Edited byDamPee Monday, August 17, 2009 12:15 PMlayout change
-
| | DamPee Monday, August 17, 2009 12:14 PM | Thanks DamPee. I am grate ful. I use Ado.net and DataSet with that but not data table. So what shall I do. Do i have to change the structure from Data set to Data Table or i can still manipulate the xsd file where i enable the user to have new default values. I may clarify this that my user wants that he has the ability to change any of the default value at will any time. So that whenever he wants to change any value he can change it. My Idea about this is to create a new form for him where all the data coulmn with default values are displayed. Once the user changes any value and clicks the OK button, new value becomes the new default value for a particular column till he changes it again. How about this please | | Farhan Iqbal Tuesday, August 18, 2009 2:18 AM | Hi Farhan,
As far as I know, there is no direct way to modify the XSD during runtime, but I have another solution which can achieve the same goal. My main idea is to add a setting to the project which refers to the default value of the column and use that value to initialize the DataSet.
For example, I have a DataSet named MyDBDataSet, the DataSet contains a table named people and the table contains a column named id of type integer. These are the steps of my solution:
1. Add a setting named peopleDefaultValue to the project. This setting is of type integer and can be set to a proper value, such as 0. Then we can set and get this value via My.Settings.Default.peopleDefaultValue.
2. Open file MyDBDataSet.Designer.vb. Locate the InitClass method of the peopleDataTable class.
3. Add this line of code to the end of the method: Me.columnid.DefaultValue = My.MySettings.Default.peopleDefaultValue
4. When a user want to modify the default value, you can write code like this: My.Settings.Default.peopleDefaultValue = Integer.Parse(Me.TextBox1.Text)
Comment:
1. When you redesign the DataSet, you need to change the code in MyDBDataSet.Designer.vb again because the code would be regenerated.
2. When you modify the default value, all the DataSets need to be recreated to get the new value.
Let me know if this helps. Aland Li
Please mark the replies as answers if they help and unmark if they don't. This can be beneficial to other community members reading the thread. - Marked As Answer byAland LiMSFT, ModeratorWednesday, August 19, 2009 6:44 AM
- Unmarked As Answer byAland LiMSFT, ModeratorMonday, August 24, 2009 2:19 AM
-
| | Aland Li Tuesday, August 18, 2009 9:57 AM | Dear Aland thanks for answering my question. As I am a newbie, I am stuck up at the very outset. 1. How to add a setting to a project.Do you want me to extend My Namespace or you want me to add a property in Settings.Designer.vb 2. How to create a new property in settings.designer.vb. I learnt something about extending My Namespace while creating a new module and creating ReadOnly properties which can be assigned to any label or text box on a form. If I go for a simple propert, wherby i can set the value also it is not extending it. Please Help
| | Farhan Iqbal Sunday, August 23, 2009 6:13 AM | thanks Alan I have found a way it is in Menu Project > Porject_Name Properties > Settings Tab and then entering the settings you taught me to write... thanks again
| | Farhan Iqbal Sunday, August 23, 2009 8:14 AM | Farhan, I am bothered by this thread for two reasons.
1) You say that you only have a DataSet, but no DataTable. A DataSet is pretty useless without any DataTables, so I'm not sure what's up with that, or what you actually have versus what you think you have. You should take DamPee's advice about how to alter the DefaultValue in the DataTable, because that advice was totally correct!!
2) Aland's advice, which Aland marked as an answer (which, I don't agree with BTW ... marking one's own post as an answer strikes me as being a bit egotistical and I would unmark it if I could) is very flawed. You do NOT want to mess with the auto-generated stuff, because, as noted, you have to alter it again any time you re-gen your DataSet. This is a BAD, BAD, BAD answer!! Please un-mark it!!! ~~Bonnie Berent [C# MVP]- Marked As Answer byFarhan Iqbal Thursday, August 27, 2009 7:10 AM
-
| | BonnieB Sunday, August 23, 2009 4:10 PM | Dear Bonnie Thanks for the input. I have not tested the Dampee advice as yet. So I cant say how to go about it.As you have suggested i will test it on my test bed and then will be able to say something about it. As far as Aland' s advice is concerned.I have tested it and found useful. I did mess up with auto generated code as i have to alter InitClass. but this gave me an answer. See, I explain my scenario a. i have one data entry form (Form1). this form is based on a data set which has two tables basing on parent child relation ship.Against a particular parent i want to add,delete,edit and save child data. b. the child data has a default value automatically displayed once user wants to add some new data by clicking on ADD Button. c. i want to give user a flexibility to change few or all the default values of child table.this i want to provide through another form(Form2).Just by opening Form2 and entering desired NEW Default values it shoud be saved for any future use.Thus once user wants to add new data on Form 1, by clicking on add button, the new default values are displayed automatically. so user has the flexibility to change the default values as many times as he wants. I have a data tier where all the data adopter and data set code is written.i have added one line in the code to refresh the data set whenever it is accessed and then fill the data adopter again.So every time this particular data is loaded on Form1 it has new value in data set as set by user through Form 2 so what you say, still Dampee advice be followed thanks | | Farhan Iqbal Tuesday, August 25, 2009 5:49 AM | >>so what you say, still Dampee advice be followed<<
Yes. Since this default needs to be saved somewhere, saving it to the .xsd is NOT going to get you anything ... it will never be recompiled into your app, thus you'll never see it.
Since you're using a data adapter, I'm assuming you have a database. THIS is where you should be storing default configuration ... in the database. You need to define and use a configuration table to store such user-configurable information. And then, using DamPee's advice, set the DefaultValue programmatically based on the value you've retrieved from the database configuration table. ~~Bonnie Berent [C# MVP] | | BonnieB Wednesday, August 26, 2009 3:40 AM | Dear Bonnie Berent Thanks. Your suggestion of a configuration table in a data base and then accessing it for changes in default value is quiet note worthy.wow.I have never thought of it and the whole thing now seems very understandable. Thanks again.YOu made my day
| | Farhan Iqbal Thursday, August 27, 2009 3:11 AM | You're quite welcome Farhan. Always glad to help. =0) ~~Bonnie Berent [C# MVP] | | BonnieB Thursday, August 27, 2009 3:39 AM |
|