473,320 Members | 1,848 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

String was not recognized as a valid DateTime.


I have a Datagrid that I'm trying to use to update a SQL table. The grid
works and I get the EditCommand to work. When I make a change to a
field, I get a date error. I was getting invalid cast error, but I
changed my Update script. All the scripts I found seem to work up to
that point. What am I missing? BTW-Im using c#.

Here is my Update Script, nor the datetime cast within the parameter
assignment:
private void DataGrid1_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{

//--retrieve textbox controls from datagrid---//

string iID = e.Item.Cells[1].Text;

string dtDate = e.Item.Cells[3].Text;

string strMeal = e.Item.Cells[4].Text;

string strLodge = e.Item.Cells[5].Text;
//---assign parameters---//

this.sqlCommand1.Parameters.Add("@TripDate",Conver t.ToDateTime(dtDate.ToString()));
this.sqlCommand1.Parameters["@Param1"].Value = strMeal.ToString();

this.sqlCommand1.Parameters["@Param2"].Value = strLodge.ToString();

this.sqlCommand1.Parameters["@id"].Value = iID;
//---execute update query script---//
// this.sqlConnection1.Open();

// this.sqlCommand1.ExecuteNonQuery();
//---deselect row for edting---//

this.DataGrid1.EditItemIndex = -1;

this.DataGrid1.ShowFooter = true;
BindGrid();
//---debugging code---//
Response.Write(Convert.ToDateTime(dtDate.ToString( )));

}

--
hodgesp
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Apr 1 '06 #1
1 2135
Hi hodgesp,

If after you click Edit button, some field become textboxe, in
datagrid_UpdateCommand event, you should get the textbox first. Then retrieve
data:

TextBox txtDtDate = e.Item.Cells[3].Controls[0] as TextBox;
string dtDate = txtDtDate.Text;

HTH

Elton Wang
"hodgesp" wrote:

I have a Datagrid that I'm trying to use to update a SQL table. The grid
works and I get the EditCommand to work. When I make a change to a
field, I get a date error. I was getting invalid cast error, but I
changed my Update script. All the scripts I found seem to work up to
that point. What am I missing? BTW-Im using c#.

Here is my Update Script, nor the datetime cast within the parameter
assignment:
private void DataGrid1_UpdateCommand(object source,
System.Web.UI.WebControls.DataGridCommandEventArgs e)
{

//--retrieve textbox controls from datagrid---//

string iID = e.Item.Cells[1].Text;

string dtDate = e.Item.Cells[3].Text;

string strMeal = e.Item.Cells[4].Text;

string strLodge = e.Item.Cells[5].Text;
//---assign parameters---//

this.sqlCommand1.Parameters.Add("@TripDate",Conver t.ToDateTime(dtDate.ToString()));
this.sqlCommand1.Parameters["@Param1"].Value = strMeal.ToString();

this.sqlCommand1.Parameters["@Param2"].Value = strLodge.ToString();

this.sqlCommand1.Parameters["@id"].Value = iID;
//---execute update query script---//
// this.sqlConnection1.Open();

// this.sqlCommand1.ExecuteNonQuery();
//---deselect row for edting---//

this.DataGrid1.EditItemIndex = -1;

this.DataGrid1.ShowFooter = true;
BindGrid();
//---debugging code---//
Response.Write(Convert.ToDateTime(dtDate.ToString( )));

}

--
hodgesp
------------------------------------------------------------------------
Posted via http://www.codecomments.com
------------------------------------------------------------------------

Apr 1 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Sterling Ledet | last post by:
I am trying to create a web service that takes a string from my web server in the following format: Mon, 6 Oct 2003 18:39:47 UTC and put's in a datetime so it can then be reformatted in C# as...
1
by: adolf garlic | last post by:
I'm having a problem with dates. (No not the sort that you have at christmas) I have a webform with a text box and a calendar control. You can either - enter a date manually (we are talking uk...
0
by: RSH | last post by:
I am having a bit of trouble filling a datatable with a query. I'm getting the error message: System.FormatException: String was not recognized as a valid DateTime. at...
6
by: Rookie Card | last post by:
I know this is a very common issue but cannot find a thread that resolves the issue. I need to re-format my dates to "MMM d, yyyy". The problem I have is I have an MSSQL database that allows...
1
by: database | last post by:
I AM FACING A PROBLEM WHEN I ACCESS ONE OF THE PAGES. IT USED TO WORK BEFORE BUT AFTER RESTARTING THE APPLICATION SEVER IT GIVES THE FOLLOWING ERROR. - Server Error ...
1
by: Scott Holman | last post by:
I'm connecting to a java web service that defines the following complex type in the wsdl <xs:complexType name="employee"> <xs:sequence> <xs:element minOccurs="0" name="firstName"...
10
by: mercea | last post by:
hi all, i'm trying to insert the time/date a button was clicked on a gridview and it generates an error:the string was not recognized as a valid DateTime.There is an unknown word starting at index 0...
0
by: Andres Bohren | last post by:
Hi i have a GridView and have Problems to put the values into the right Datatypes. Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As...
4
by: dhanashivam | last post by:
hi, in my web application i am getting date values from sql server database and store in the datatable. it works fine when i use the US culture. But when i change the culture to british i am...
3
by: lucindaa | last post by:
Hi, i have a string variable having date as following format "05-01-2010" when convert this date into DateTime Format i got the following error 'String was not recognized as a valid DateTime'...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.