DataSource Controls :: Updating SQL Data Fields By Field Index?
Jan 7, 2010
I have a situation where I have a file with each Account Record contains Monthly Expense Total Fields and Monthly Budget Fields for 2009, 2008 and 2007. I'm working with 72 fields (36 Expense and 36 Budget).
Need to create New Year Proceure that will shift data from 2008 to 2007, 2009 to 2008 and move Zeros to 2009 for both Expenses and Budgets.
I can do this using Parameters and Update SQL but I am under the impression that I must specificaly name each field in defining Parameters and SQL Update Command.
Since all fields are sequential withing a record, is there a way that I can use a For/Next loop to index my way through the fields moving data from one year to another?
When using DataReader I'm able to use reader.item(index) to access data record fields.
I have a datatable for which i'm defining a dataadapter. I'm specifying an updatecommand with sqlparameters for the dataadapter I set the updatecommand's parameters using the following overload:
[Code]....
The length 16 is used because this is the length of the field according to sql (the image datafield is a pointer of size 16) I noticed .Net is actually truncating the string because of the length i'm setting. An image of size 3kb will properly upload if we set the length field to be greater than 3kb The question I have is what is the proper value (or strategy) to use in order to set for the length field so that ALL images will properly update to the database, with each using the appropriate size.
I guess i could theoretically set the length to be maxint, but this seems sloppy. Looking at sqlparameter documentation i didnt see an 'unlimited' or 'default' length i could set, which would allow each update statement called to use the appropriate size for the data length for that row.
ive a DB in access with a single table and no primary key, actually i dont need a primary key but i can consider a date field plus another to make an index. however i want to add a counter field based on every change of date field, for instance ill have many records of 20/May and all must have the same id then when the date is different, the next group of records with that new date must show 2 etc.. is it a quick way to update my database?
I have detailsview with a SQLDataSource to 1 table (City) and am referencing another table (Unit) for one if it's fields.
[code]....
I changed the Unit Code (City Table) field into a template field and am using a dropdownlist item to reference the Unit Name from the (Unit Table) with the CityTable.Unit Code = UnitTable.Unit Code. However when I go into the update and change the dropdownlist item to another Unit Name it is keeping the original Unit Code value or it might even be selecting the first value from the dropdownlist item.
I've got a gridview with three fields, the last of which is a template field with an imagebutton in.
The first field is a Date, and the second is a time field (it is however just varchar field as it may differ and will not be programmatically used).
I want the following to happen if I click on the imagebutton (reserve):
Four other fields must be inserted into the record.
Is the best way to launch a detailsview where the row.imagebutton@=ID and just edit the fields like that or should I pass the two fields (and RecordID) along with the query string to a new page where the passed information can be in invisble textbowes and just have the user enter (UPDATE) the four outstanding fields? I feel like doing it this way?
can read on 1. setting up the onrowcommand code for the templatefield 2.
This should be simple as it is only one table with records that has to be partially inserted by an admin person (2 Fields) and then completed by a web user (4 fields).
I have a relatively complex dataset (numerous tables, some with multiple records) generated from reading in an XML file. I need to connect said dataset fields to an ASP form. At the moment I'm assigning them manually, like so in the pageload:
I did some looking into binding the textboxes (and dropdownlists, and checkboxes, and and and...) directly, but it seemed to be too many formats to use.
So this works fine, but as the number of fields increases, those load and unload lists are going to get unwieldy.
I have a listview control bound to an SqlDataSource. As part of the formatting I want to add a title to the data returned from my database. For instance if the data base returns a phone number I want to add 'Tel.' first. However I do not want to diplay this title if the datafield is empty. Here is what I have done so far.
Business is a phone number. If the data field contains a number I get: Tel. 1234 123456. If the field is empty I get Tel. If Business is null I want nothing dsplayed, how do I do this?
I have a grid view attached to a custom query. The query selects data and the address data in the database is split into different fields like street_address1, mail_zip etc. etc. What I would like to do is display all the address data fields in my database in one field on the Grid View.
I have a gridview where I am using the update. I have converted the label into a templatefield and added a dropdownlist which is getting polulated in the Rowdatabound event. When I test the update i get an error
Cannot insert the value NULL into column 'StartTime', table 'HTC.dbo.EventDates'; column does not allow nulls. UPDATE fails.The statement has been terminated. so I am ussuming its still trying to update from the label rather than using the dropdownlist. here is my code:
I'm using a formatting expression with a template field. When the details view goes into edit mode the formatting is applied. It looks great because it applies the currency formatting. It shows up as "$60,000.00" instead of "60,000.0000". But then when I do the update it gets rejected because of the $. Is there a way to keep the formatting for the user to see in edit mode but remove the $ when doing the update so I don't get the error?
The error: Exception Details: System.FormatException: Input string was not in a correct format.
I have a Modified Date and Modified By column in my gridview and I want them to be updated with the current date and current user any time a user updates the row.
I converted my columns to template fields and the textboxes in the edititemtemplate are bound to my sql data columns "ModifiedDate" and "ModifiedBy"
Then I added the attached code in my RowUpdating event.
When I test the code and click the Update link on my gridview I don't get an error but the values don't update either. I put a breakpoint on the code and when I hover over "ModifiedDateLabel.Text" I see the old value of the field so I know I'm accessing the control correctly.
The original Item Template was Enabled ="false" I changed this so that you did not have to set the row to a state of edit in order to just select a row. I enabled it so that you could "select" any row with out putting it in a state of edit. the only value changing is if its selected or not. What i am trying to do is use the Data Source Update method to update the bit in the database based on the check box. Currently Update() returns 0. I believe this is because the row/feild is not marked as changed so the Data Source does not see it as something that needs to be updated.
What I am hoping for out of this is post is a way that the rows whom check value has changed to be marked as changed/edited so that the data source will update the database with the values of the check boxes. If all rows are updated this is acceptable as well. I know this is a super simple solution but i have been out of the .NET for a little bit.
I have a gridview based on a sqldatasource that has some colums from which two colums showing the data of two fields: field1 and field2. field1 is an ID which should not be updated and therefore it is readonly=true. The sql-query from the sqldatasource is:
SelectCommand="SELECT field1, field2 from anyView"
What I want is, that when a row is updated, then the value from field1 should be copied to field2 The update-query is:
UpdateCommand="UPDATE myTable SET field2=@field2 WHERE field1=@field1"
My idea was, that the @field2 paramter gets the value from the query string out of field1:
But this does not work. Is there an easy way to copy the data from field1 to field2 when updating the row? In addition, is this possible, even if field2 ist not shown in the gridview (i.e. field2 is selected in the query but is not a field in the gridview but should be updated with value of field1).
Cannot create the clustered index 'RateViewIndex' on view 'NoteToPass.dbo.RateView' because the select list of the view contains an expression on result of aggregate function or grouping column. Consider removing expression on result of aggregate function or grouping column from select list.
I have a gridview and sqldatasource in a form. My sqldatasource has select,delete and update command. The delete command is working but the update doest not work when I click the update command field.
I created a gridview that is bound with an SQL datasource - I added a gridview button column. I need to update/insert 'Y' on a specific cell in the row when I press the button
This is my gridview code
[code]....
The button column I have says delete on it but it shouldn't really delete it - Once I press the button it puts a 'Y' on a column that is filtered out by my sql statement in the sql datasource
Scenario: I am creating a custom gridview control which has a custom CheckBoxTemplateField column (deriving from TemplateField class). This template field column has custom Checkboxheadertemplate (implementing ITemplate) and CheckboxItemTemplate (also implementing ITemplate). In InstantiateIn method of both templates (header as well as Item template), I am adding a checkbox control which has Autopostback = true.
My requirement is: I want to mark all the values in the binding column of datasource if checkbox in headertemplate is checked. I dont want to mark only rows visible on grid. I WANT TO MARK ALL ROWS IN DATASOURCE. I want to do this in _CheckedChanged event of checkbox in header template.
Problem I am facing: When I check/uncheck the checkbox in header, it postbacks. so in OnCheckedChanged event, gridview's datasource is null. Secondly, in any event of gridview, I could access only those rows of datasource for which corresponding rows are visible in gridview through Gridviewrow.DataItem property. But I want to set it for all rows in datasource.
I changed a text field to a template field assigning the selected text and the selected value is being assigned to another currency field also templated. I get aa error
[FormatException: Input string was not in a correct format.]
This is the sqlDateTime overflow problem again. Background. As I'm sure you know dates must be between 1/1/1753 and 12/31/2999. If you have an empty date field, it throws and exception. So I created a function (below) that solve the problem when attempting to update or insert a record with a date field. Works great.
Public Shared Function MakeDateField(ByVal pasDate As String) As Nullable(Of DateTime)
If IsDate(pasDate) Then Try If pasDate <= System.DateTime.MinValue Then Return Nothing Else Return CType(pasDate, DateTime) End If Catch ex As NullReferenceException Return Nothing End Try Else Return Nothing End If End Function
So I thought about using a time field. I have the field, have the validator in place and then attempted to test the page. It resulted in my least favorite error message "sqlDateTime overflow".
I can think of several workarounds like adding a date or a fixed date to the time field, or converting it to a string. Each of these is problematic.
IS THERE A BETTER WAY TO UPDATE/INSERT TIME FIELDS.
I'm hoping someone can point me in the right direction. I will be as detailed as I can in explaining the issue;I have a dataset I have instantiated in a class file (vb.net), and fill the data succesfully. That data is then dumped into an excel file. What I need to do is to go through all the data in the dataset, and directly update the database, changing a "status" column from "pending" to "processing" based on the store number. As I am new to datasets (relatively speaking, of course), I am not quite certain how to accomplish this task. Below is the code I have so far:
[Code]....
If anyone could provide sample code to use, or could provide a quick bit of code I could just copy and paste in and test,
I am making shopping cart application.On Viewing Shopping Cart,when i try to update the quatity of product column it permit me to edit but wn i click update link.the gridview disappears wid all products.send me some code snippet in C# as i want only quantity column to be editable.I am using the following code:in Code behind File