Error editing data records in gridview when using convert function.

Hello, i currently have a gridview that is populated with data from a SQLServer datasource. I have put an output mask in the select statement, so the date and time attributes are displayed in the format i prefer them to be in. SELECT PatientNo, ConsultantName, HospitalName, CONVERT (varchar, Date, 101), CONVERT (varchar, Time, 8) FROM [Appointment];

 However when i click the 'edit' link for a record in the gridview, i am unable to edit the date/time attributes and when i click update to confirm any changes to the other attributes, the values in the date/time attributes are emptied. How can i solve this update problem. I'm guessing i need to configure my SQL UPDATE statement, but bit stuck how i do this. Please help!


James Cool

1/24/2008 5:41:15 PM 29906 articles. 0 followers. Follow

9 Replies

Similar Articles

[PageSpeed] 58

How do u have the Datetime value in ur Gridview like... is it a Bound field or a Template field with a text box. if its text box then pass that field on to the update statement.


Hope this Helps


1/24/2008 6:23:30 PM

It is a bound field. When the edit link is clicked, text boxes appear for editing the values of each attribute, excluding the date/time attributes.

1/24/2008 10:48:35 PM

are u storing the current date or is the date  historic. If its the Current then in your update sproc give fieldName = GetDate(). If its a historic date and if you are not gonna update it any time... just dont call that field in the sproc...


Hope this helps..



1/25/2008 1:57:51 PM

hi karen,

 whats the sprog? i'm simply creating a SQLServer data source, then binding that to the grid view. when i click edit, it will not let me update the date and time attributes. when i click update, the values of date and time both empty.

thanks, James.

1/25/2008 10:41:26 PM

Sproc means Stored Procedure...Is ur date the current date or a historic date???

1/28/2008 3:29:32 PM

Its a date in the future.

1/28/2008 10:18:30 PM


From your description, it seems that you are unable to update the datetime field when click the edit button in GridView, right?

Since you have use CONVERT function in your sql, that means the output type of datetime has changed to be varchar. When you edit the cell, you have passed the varchar typed value to the update command, and of course the format of value you passed cannot match the datetime filed in your data table.

I think you can re-create the date time value after you got it from the UpdateParameters, for example, when users has input “01/30/2008”, you can convert it to a long datetime format, such as “2008-01-30 00:00:00:000”, and make such value be the updateparamter which would be put into the update command.

You can use Updating event of SQLDataSource to perform such initialization operations that are specific to your application, to validate the values of parameters, or to change the parameter values before the SqlDataSource control performs the update operation.


Michael Jin.
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
1/30/2008 6:06:55 AM

Hi, thanks for your message. Do you know the sql that i could use in the update statement to convert the varchar date format back into the datetime format?



1/30/2008 12:50:37 PM


In Updating event of SqlDataSource, first you can retrieve the original data value from the textbox (which is inputed by users) by e.Command.Parameters["ParameterName"], and then re-assign the converted value to the update parameter collection. Here's the code for converting.

        string original_date = "01/30/2008";  // original_data is the value retrieved from  users.
        DateTime date;
        date = DateTime.Parse(original_date);
        string datetoupdate = date.ToString();  // datetoupdate is the value to pass into update commands.

As for the update sql command, you don't need to change that, something like

update table set DateField=@ParameterDate

Just make sure that the parameter name matches the one in parameter collection.


Michael Jin.
Microsoft Online Community Support

Please remember to mark the replies as answers if they help and unmark them if they provide no help.
1/31/2008 2:41:52 AM

Similar Artilces:

Converting a gridView using an Sql Datasource to a gridview who is not using an SQL DataSource
How can i rewrite this page so that i doesnt make use of an SqlDataSource?  <%@ Control Language="C#" AutoEventWireup="true" CodeFile="LoginHistory.ascx.cs" Inherits="Private_UserControls_WebUserControl" %> <html> <head> <%--<link rel="stylesheet" href="BaldwinPortal.css" mce_href="BaldwinPortal.css" type="text/css" />--%> <title>Login History</title> </head> <body style="margin:0 0 0 0;padding:0 0 0 0"> ...

enable editing from detailviews task:) error message is use convert for uniqueidentifier.. i cant edit my record from detailview.
hello friends i have use enable editing from detailviews task:) error message is use convert for uniqueidentifier when i edit and uptade my record.. i cant edit my record from detailview. what is problem ? where can i use convert for uniqueidentifier column ? cheersMark as me if my question or my answer can be helpful for you :) hello friends i have solverd this problem..sqldatasource > configure data source and i have deleted to uniqueddentifier field from update of configure select statement (specify custom SQL statement or stored procedure) cheers :)Mark as me if my questio...

Not able to use sql Convert function in gridview
 Hi!Im trying to get europe time in one of my gridviews (instead of am/pm format), and tryed using following select-string:SelectCommand="SELECT Convert(DateTime, vagt.start, 13), vagt.***, medarbejder.fornavn + ' ' + medarbejder.efternavn AS Expr1, medarbejder.medarbejder_id, vagt.vagt_id FROM vagt INNER JOIN medarbejder ON vagt.medarbejder_id = medarbejder.medarbejder_id WHERE vagt.dags_id = @intDagsid" The thing to note ofc, is the Convert() part. Now, when i use that method on the "vagt.start" column, it gives me an error stating it cant fint a field...

SQL Update from Editable Datagrid not 'seeing' editted data
Datagrid is displayed with all the right data (data retrieved in Load_Data() using doc_id passed to .aspx). Two fields in datagrid are edittable. If data in fields is changed and btnUpdate_click is executed (executed via onclick event in button at bottom of datagrid) the UPDATE command IS actually updating the database HOWEVER it is NOT using the editted data, but rather the original data. I've read 100 differnt posts about not rebinding the data, etc. and I'm not rebinding the data. The code I have is actually from the samples (

Submit Form to insert data into SQL and display with a gridview (edit as well) below how do i insert data into sql table?
I have an page that has a simple form where a user can submit customers information. Below that I have a gridview which displays customer information submited by the user who is logged in. I have the gridview displaying, sorting and updating as I want however I can't figure out how to bind a button click to insert data into the customer table and then have it refresh the gridview when they submit. Here is the basic code; (I am using AJAX for a calendar when a user wants to edit an appointment date) &lt;div class="leftBar"&gt; <div align=center&...

how to delete a record in the data base using Linq(sql server 2005 express edition database)
following is the code which i am trying to use it throws an error and dosent work.  error details: Unable to cast object of type 'System.Data.Linq.DataQuery`1[tbl_temp_bank]' to type 'tbl_temp_bank'.  source code(aspx.vb file)  Dim c As New temp_business_bankDataContextDim tag = From t In c.tbl_temp_banks Where t.TIN = Convert.ToInt32(tin.Text) Select t c.tbl_temp_banks.DeleteOnSubmit(tag) c.SubmitChanges()   please can some one help me with this.thanks Hi duminda_dayan, Your codes have two incorrect places. Please take a look at this sample...

need code for updating gridview in .NET 2.0 without using sql data source
hi,this is satish,I have faced problem to update the gridview with template columns in .NET 2.0 without using sql datasource.So please send me the code with events for updating gridview with teplate columns including one dropdownlist inatead of textbox without using sql data source.i hope you will understand my question, please send the answer ASAP.Waiting for reply,regards You will need to deal with it as if it was a traditional GridView in ASP.NET 1.x. Hope this helps! Hammoudeh AhmadWE never know how high we are ... Till we are called to rise And then, if we are true to...

Using GridView to edit and update the Data without using SqlDataSource
Hi,  I am new to ASP .Net. I am having a GridView control and I want to bind data to GridView using DataSet.   SqlDataSource should not be used because it should be done programatically.  Also, the GridView should also support editing the data and update the same into the database.  Can you supply me with a piece of code .     Regards, Rajesh KalidindiMicrosoft Certified Technology Specialist Try to search in google for dynamic add record to gridview , choose ur code language following is one of the link i found

How to change the SQL used for the GridView, when using a control parameter in the datasource
I'm using a GridVeiw with and Access database. I want to allow users to select a date and then update the GridView to show only data entered after that date. So my question is, how do I modify the SQL used by the datagrid? I'm using a control parameter as part of my AccessDataSource and I think that is what I'm having trouble figuring out how to include. Here is my datasource, with the control parameter in the the GridView. The GridView works fine with these initial settings settings. <asp:AccessDataSource ID="AccessDataSourceForwView" runat="server" ConflictDetection="Compa...

used a to converter and am now getting a syntax error.
ok I used a cool utility at to convert some to and it spit out a bunch of code which almost works but I am getting a syntax error on this line Imports (StreamReader sr = Shadows Function)() As StreamReader(objResponse.GetResponseStream()) I tried it that way and also like Imports (StreamReader sr = Shadows Function)() As StreamReader(objResponse.GetResponseStream()) but either way gave the same error Compiler Error Message: BC30035: Syntax error. Source Error: Line 26: Line ...

How to Data Transfer From Excel to Microsoft SQL Server Data base Using .Net.
Hai All, How to Data Transfer From Excel to Microsoft SQL Server Data base Using .Net. I have one Excel Sheet in that sheet 15 Fields (attributes) and 3000 records are there. In this 3000 records i want to store this (Excel) data into  5 related tables on Sql Server Database Using .Net.   How to store Excel Sheet data into Sql Server database. Please help me as soon as possible. Thank You Very Much...Have a Good Day... With RegardsSridhar...

how do i insert data into sql server using data from textboxes and sql connection and sql command
anyone can give me a simple explaination and code.. Thanx in advance Take a look @ Sample Code: How to add...Sushila Bowalekar PatelVisual ASP/ASP.NET MVP There are a lot of tutorials out there, but I know they can be a bit confusing as they all approach things slightly differently. Basically a nice simple version would go like this:' *** First set up your connectionDim conConnection As New SqlConnection("server=servername;database=yourdatabase;uid=yourname;pwd=yourpassword;")' *** This line takes care of your sommand text and command connection in one ...

Gridview Data editing error
Dear Sirs,  I am very new to programming and I have a problem why i am writing here with hope. First I have a dropdown list from where i select a group. once i have selected a group i will get some data from an SQL server. Now my next step is to edit these datavalues. What i did was simple enabled the Autogenerated Edit thing .. The buttons show up fine but I get some error. can someone analyse the error and tell me the exact problem please ? Server Error in '/' Application. The GridView 'gwPersoner' fired event RowEditing which wasn't handled. Descrip...

Editing data using gridview
Hi! I have tried to code the following to edit data using gridview control. I am able to successfully update the CategoryName into the data table. Hoever, I am not able to update the selected hex value for the color. I am not sure on how to do that. I hope someone can help me. I am using for the coding. addCat.aspx <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AllowSorting="True" AutoGenerateColumns="False" CellPadding="4" DataKeyNames="Cat...

Web resources about - Error editing data records in gridview when using convert function. -

GridView SelectedItem Binding Gotcha in WinRT
Last night when I was doing some WinRT hacking I was trying to setup databinding to the selected item in the GridView control and I ran into ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Advanced Search Gridview Latest News Releases All ...

CNW Group
... Services Beyond the Wire About CNW my CNW CNW Access CNW Directories Financials Webcasts Events my CNW All News Releases Advanced Search Gridview ...

CNW Group
Home Services Beyond the Wire About CNW Financials Webcasts Events My CNW All News Releases Add a Filter Gridview Latest News Releases All Today ...

New CmdLets of Powershell 2.0
New CmdLets of Powershell 2.0

Price Drop: Softbox
... objects- create product reflection- changing the background with something more interestingUse it as:- softbox- honeycomb softbox- gridview ...

Profile.aspx: ASP Alliance
.NET,ASP,ASP.NET,SQL,XML,HTML,ADO,ADO.NET,JavaScript,JScript,CSharp,VBScript and VB tutorials from AspAlliance.

Quick Answers - CodeProject
Questions - Free source code and tutorials for Software developers and Architects.; Updated: 25 Oct 2012 - Upcoming stories is a community based news site edited by our members. It specialises in .NET development techniques, technologies and tools including ...

View Features - ExtendASP
Call 847-681-9827 or Request a Demo View Features Testimonials Pricing About Us Coming Soon ExtendASP exposes every feature, more than any other ...

Resources last updated: 1/18/2016 3:55:50 PM