|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Default values on new rowHi.
I have a WinForms app and a SQL Server database. When the user adds a new row to a table (say table Orders with columns OrderNo and CustNo ), I want to programmatically supply values for CustNo (current user) and OrderNo (number of orders by customer CustNo incremented by one). What is the standard way to do this? Should I subscribe to some event, like TableNewRow or, should I perhaps do it on the database level (triggers)? Any advice would be appreciated. Gudni How is the user adding the new row? Are you providing them a way to do it?
In which case, you should do it in the same place. Additionally, look into the DefaultValue property of columns in a DataTable (I am assuming you are using one, you didn't provide a lot of detail), you can set some defaults up that way. Or are you trying to do it right as the insert as being done in the database? I don't see how triggers would do it - your trigger wouldn't have the username of the user in your application. It's very hard to answer without getting more specific details. Show quote "Gudni G. Sigurdsson" <GudniGSigurds***@discussions.microsoft.com> wrote in message news:3D802F63-65D9-4736-A0AF-77FD833745DB@microsoft.com... > Hi. > I have a WinForms app and a SQL Server database. When the user adds a new > row to a table (say table Orders with columns OrderNo and CustNo ), I want > to > programmatically supply values for CustNo (current user) and OrderNo > (number > of orders by customer CustNo incremented by one). What is the standard > way > to do this? Should I subscribe to some event, like TableNewRow or, should > I > perhaps do it on the database level (triggers)? Any advice would be > appreciated. > Gudni Hi Marina and thank you for your response.
I have a dataGridView, a bindingSource and a bindingNavigtor wired up. The data source of the binding source is a table in a dataSet contained in a DAL module separate from my UI module. When the user clicks on the addNewItem button in the binding navigator, I want to generate my default values. I have come up with a way to do this. In the bindingNavigatorAddNewItem_Click event handler, I check the last row in the grid, take the value of OrderNo and increment it by one. The value for CustNo is known from elsewhere. This works, but I suspect that it should preferably be done in the DAL module at the database level? Also, I might have instead of a dataGridView a detail view of a single record in my (Orders)table. I could probably do something similar, but when I started to think about this problem, I imagined that I would run a query against my database down in the DAL module to find out the last OrderNo for the current CustNo. This is perhaps unnecessary complicated. I would appreciate any suggestions. Sincerely, Gudni Show quote "Marina Levit [MVP]" wrote: > How is the user adding the new row? Are you providing them a way to do it? > In which case, you should do it in the same place. > > Additionally, look into the DefaultValue property of columns in a DataTable > (I am assuming you are using one, you didn't provide a lot of detail), you > can set some defaults up that way. > > Or are you trying to do it right as the insert as being done in the > database? I don't see how triggers would do it - your trigger wouldn't have > the username of the user in your application. > > It's very hard to answer without getting more specific details. > > "Gudni G. Sigurdsson" <GudniGSigurds***@discussions.microsoft.com> wrote in > message news:3D802F63-65D9-4736-A0AF-77FD833745DB@microsoft.com... > > Hi. > > I have a WinForms app and a SQL Server database. When the user adds a new > > row to a table (say table Orders with columns OrderNo and CustNo ), I want > > to > > programmatically supply values for CustNo (current user) and OrderNo > > (number > > of orders by customer CustNo incremented by one). What is the standard > > way > > to do this? Should I subscribe to some event, like TableNewRow or, should > > I > > perhaps do it on the database level (triggers)? Any advice would be > > appreciated. > > Gudni > > >
Other interesting topics
|
|||||||||||||||||||||||