Forms Data Controls :: Trying To Looping Through A Data Table And Update A Column On Each Row
Jan 17, 2010
I am trying to looping thru a data table and update a column on each row. However after updating I am getting both before and after update records in the data table. Assuming there is only one column called "Qty" withing the data table and I want to double the value in the column. I use the following to perform updating but not getting my expected result.
I am working on a web app for an online photo album. It is the last project in Scott Mitchell's book: "ASP.Net 2.0 in 24 hours".
I am creating a page where users can enter new photo images. The functionality for uploading an image will come later. I am working on just inserting a new row into the Pictures table with an optional category, a required title and a required description.
I am getting an error when I try to insert a new row.
Here is a screenshot of the page with a shot of the dropdown list.
The Categories are user-specific. I am getting the correct values retrieved.
[URL]
There are two pretty simple database tables involved here.
NOTE: The CategoryID and PIctureID are both autoincrement integer columns.
[URL]
The page uses a DetailsView that uses a SqlDataSource that uses the Pictures table. (The DetailsView's Default Mode property is set to "Insert". The "Enable Inserting" checkbox is also checked.)
The dropdown list uses a dropdown control that uses a SqlDataSource that uses the Categories table.
When the "Insert" button is clicked the CategoryID value associated with selected (Category) Name on the dropdown list will be used along with the Title and Description values to insert a row in to the Pictures table. (If no Category value is selected, then a null value will be used for the CategoryID. This is OK because the CategoryID column in the Pictures table allows nulls.)
My problem is that I am getting this error:
Cannot insert explicit value for identity column in table 'Pictures' when IDENTITY_INSERT is set to OFF.
(FYI: I have the full version of both Visual Studio and SQL Server.)
What's the best way to do this? After I load my DataTable from SQL, I'm looping through it with a For Each...Next loop performing some calculation for each DataRow. If the values don't fall within a certain threshold, I want to remove that Row. However I can't just do a MyDataTable.Remove(MyRow) or it breaks my For Each loop.
I've got a single table, with project information and schedule information. To make the data easier to present, I created a tab control with two panels (a detailsview in each). The first tab is for project info, the second tab is for schedule info (again, all fields in the same table). The problem is, if i change info in both tabs, and then hit the update button, only the data from one tab is added to the table. I think this problem is simple to fix, and boils down to the way I have the page organized, but I can't quite figure it out.
I've boiled my code down to the following conceptualized structure:
[code]....
When you click the update button, you return to the listview, but with only the information from your current tab saved. How can I get it to update from both detailsviews?
I have created a gridView control and have successfully bound DataTable (dt) to it using
[Code]....
However, I want to add a dynamic hyperlink that will take the user somewhere based on the value of one of the columns in the selected row. I'm not sure how to do that.
I've got a gridview that is databound with LINQ in the code behind. One column shows the id from the table. I would like to show a more human friendly product name that is associated with that id number but is from another table. Thought I had it figured out by entering a Template field in the gridview tags (in the .aspx page) and an item template within that with
I have a gridview which I have databinded via the quick config facility, but I need to databind one column to a completely different sql table data field - how do I do this?
If I go into Gridview tasks and select the column and edit the data binding parameter but what is the format for a table outside the source definition for the the rest of the gridview?
I want to copy data from a table[tblExcel][No.of columns:2] to another table[ev_event] which has 5 columns, 2 columns from the another table, 3 columns from user defined value
I have a gridview that gathers data from two tables, an orders table and a products table. I have an OrderQuantity from the Orders table and a StockQuantity from the Products table and a button to process the order.I am trying to move through the GridView one line at the time, substract the OrderQuantity from the StockQuantity and update the Product table.
I have a gridview with an edit command button. When I press the edit button, it makes all the columns of the selected row editable. But I want it to make only few columns of the selected row to be editable...how can I do that?
what I have to add/subtract from the following listview to change the table and column width. All my attemps like the style="width: 50%" have no effect.
One of the headers I used is shown below,In this I dont want to display the mobile phone number field so I removed that field even then in the output it is showing me the column mobile number...what is wrong?watelse should i change?
I have an asp:Table. Its with is 100%. This table has only one row but 6 columns. The width of first 5 column is fixed at 150px. The last one does not have its Width specified and so it takes up the rest. The whole row has a background. If any of the first 5 column is clicked, the background of that cell is changed to white.In my development computer, the last column has about 250px. Yet in user computer, as the monitor has a smaller resolution, the last column has only 30px or so. User complains it is ugly and wish to merge the last column with the previous one. How to do so?
I just wanted to know if there is any way to dynamically set the width of a column inside a table within a datalist based on the length of the text fetched from the database.I am inserting my code.
I have a gridview that is populated with rows of 4 columns.
2 of the columns are required as parameters and I do not want these displaying so I coded visible = False.
The other 2 columns, whilst visible, I coded readonly = True, as all that is required is for the user to select a particular row of data, and select it for edit.Then, the update should be pressed.
Am trying to build a page that will display one record at a time. That is the user searches a records table and the page displays the record. Than when the user us done making any changes and clicks save, i want the page to update the records table. So far, i have the page displaying the search results, but the save functionality is not working. Actually after changing an entry and the save button is clicked, the records change are currently reverting back to the old data that they want to change it from. How do i go about updating the records in the database? Here is the code that I have been able to come up with so far.
I have followed an online Microsoft tutorial that walks through building a Northwind.xsd that includes ProductsTableAdapter and a few other such table adapters (http://msdn.microsoft.com/en-us/library/aa581776.aspx).
Question: I now see a update column at the start of each row of the datagrid for AllProducts page. When I click update on a row and change the value of one of the non-primary fields (ex. Productname) and press Update, I get the following error:
The GridView 'GridView1' fired event RowUpdating which wasn't handled. How do I implement this event handler in VB? I know that when I implement using SQLConnection and use templatefields to bind each column I don't need to implement each event handler.
Cannot insert explicit value for identity column in table 'UserDetails' when IDENTITY_INSERT is set to OFF.
I'm trying to insert a record through a BLL (Business Logic Layer) class with an 'Insert' button attached to the FooterTemplate of a GridView2. My code:
[Code]....
[Code]....
BLL layer code:
[Code]....
The field 'idUser' is autoincremented. When I use SqlDataSource with a DetailsView, add option it adds a record and autoincrements the 'isUser'.