Hi,
I will explain my problem. I have to give one datetime format to system and i have to store that to database then i have to view the current datetime in that format. This i did, its working perfectly. Then i have to enter some user datetimes and i have to store that , it may in any format. But i have to view this only stored format. This is my requirement.
I got problem in converting, String was not recognized as a valid DateTime. This my error. i will give my coding below.. please help me to clear this one..
Public Shared DateFormat As String = String.Empty
'This page_load will convert the user date&time to System format and display in GridView
Public Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load, Me.Load
Dim dsADM As DataSet = Nothing
Dim Format As DataSet = Nothing
If Not IsPostBack Then
Format = (Common.GetAll("SELECT * FROM DateFormat WHERE FORMATID=(SELECT MAX(FORMATID) FROM DateFormat)"))
If (Format IsNot Nothing AndAlso Format.Tables.Count > 0 AndAlso Format.Tables(0).Rows.Count > 0) Then
DateFormat = Format.Tables(0).Rows(0)("DATEFORMAT").ToString()
End If
dsADM = Common.GetAll("SELECT DATEID,CURRENTDATE,CURRENTTIME,DESCRIPTION FROM CurrentDateTime WHERE STATUS='A'")
GridView1.DataSource = dsADM
GridView1.DataBind()
End If
End Sub
'This gridview rowdatabound will assign systems stored format to user date&time
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
If e.Row.RowType = DataControlRowType.DataRow Then
e.Row.Cells(1).Text = DateTime.ParseExact(e.Row.Cells(1).Text.Trim(), DateFormat, System.Globalization.CultureInfo.CurrentCulture.DateTimeFormat)---This place i am getting that error...
'e.Row.Cells(1).Text = DateTime.Parse(e.Row.Cells(1).Text, DateFormat)--i tried this, this also have error like-- cannot convert a string to integer using IFormatProvider
e.Row.Cells(2).Text = DateTime.Parse(e.Row.Cells(2).Text, DateFormat)
e.Row.Cells(3).Text = DateTime.Parse(e.Row.Cells(3).Text, DateFormat)
End If
End Sub
Thank you
I.A.Roy lawrence
!--removed tag-->
Enter your message below
Sign in or Join us (it's free).