|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Convert string into SQL datetime value
Ok, I'm totally stuck on this one, here is what I'm trying to do.
I pull a record, and with it I pull the last modification time. Users makes changes and when they go to save them, the system checks if the modification date has changed on that record or not, basically record locking. So, I have a variable time_stamp that holds that datetime value from SQL server, but when I try to pass it back into the SQL as a parameter I get errors. I have tried so many combinations that I'm stuck. Here is the list: combo 1: Code:
Dim time_stamp As DateTime
sqlUpdateDR.Parameters.Add("@time_stamp_old", time_stamp)
ERROR: SqlDateTime overflow. Must be between 1/1/1753 12:00:00 AM and 12/31/9999 11:59:59 PM. combo 2: Code:
Dim time_stamp as String
sqlUpdateDR.Parameters.Add("@time_stamp_old", DateTime.Parse(time_stamp))
ERROR: String reference not set to an instance of a String. Parameter name: s combo 3: Code:
Dim time_stamp as String
sqlUpdateDR.Parameters.Add("@time_stamp_old", SqlDbType.DateTime, 4, Format(time_stamp, "MM/dd/yyyy hh:mm:ss tt"))
OR Code:
sqlUpdateDR.Parameters.Add("@time_stamp_old", time_stamp)
ERROR: Prepared statement '(@DR_ID int,@transfer_type nvarchar(4000),@dr_reason nvarchar(40' expects parameter @time_stamp_old, which was not supplied. I have even made a few attempts at declaring time_stamp as SqlType.sqldatetime and working wite that, but I can't do anything with that either. I'm running on a Windows machine, SQL 2000, and this is a ASP.NET application. The column that I'm taking the data from is of type datetime, NOT timestamp. Also, I have modified my T-SQL to "SET @sqlMessage = @time_stamp_old" and I'm still getting the errors. Any help would be much appreciated, I'm sure there is a way to pass a datetime value back into sql for comparison. Tetris |
|
#2
|
||||
|
||||
|
A TimeStamp is not a Date/Time, so it can't be parsed as one. A TimeStamp is a unique number that gets updated every time a row gets updated.
So there's no need to "Update" the TimeStamp field, since it gets updated automatically when any field in the row is updated. |
|
#3
|
|||
|
|||
|
I'm only calling it time_stamp, but the field type is datetime. I'm trying to kill 2 birds with one stone, have the functionality of timestamp and date modified.
|
|
#4
|
|||
|
|||
|
In the end it's just a question of : How do I pass a datetime parameter into my SQL code?
|
|
#5
|
|||
|
|||
|
PROBLEM SOLVED...datatype...DdType and SqlDbType....ahhhhh two different things.
|
|
#6
|
|||
|
|||
|
i've got this problem..any1 help me solve it pls??
i've got this codes behind the designer page.. Sub BindGridView(Optional ByVal strOk As String = "", Optional ByVal searchStr As String = "") Dim clsTickets_Obj As New clsTickets If strOk <> "" Then If searchStr <> "" Then dt = clsTickets_Obj.DBSelect(Convert.ToDecimal(searchSt r)) Else dt = clsTickets_Obj.DBSelect End If If dt.Rows.Count > 0 Then ViewState("dt") = dt End If Else If Not (ViewState("dt") Is Nothing) Then dt = DirectCast(ViewState("dt"), DataTable) End If End If If dt.Rows.Count > 0 Then gd_resc.DataSource = dt gd_resc.DataBind() End If End Sub pls help me asap..thx loadz!(: |
|
#7
|
|||
|
|||
|
any1 help me solve this pls..asap..thx(:
Protected Sub GridView1_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles GridView1.RowEditing Dim tbSubj_Subject As TextBox GridView1.EditIndex = e.NewEditIndex BindGridView() tbSubj_Subject = DirectCast(GridView1.Rows(e.NewEditIndex).FindCont rol("EditSubj"), TextBox) 'tbSubj_Subject.Text = dt.Rows.Find(Convert.ToString(ID.ToString))("Subject").ToString() = "laha" End Sub Protected Sub GridView1_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles GridView1.RowUpdating Dim tbSubj_Subject As TextBox Dim GridView1_temp As GridView GridView1_temp = DirectCast(sender, GridView) tbSubj_Subject = DirectCast(GridView1.Rows(e.RowIndex).FindControl( "EditSubj"), TextBox) Dim ClsTickets_Obj As New clsTickets ClsTickets_Obj.Subject = tbSubj_Subject.Text If dt.Rows(e.RowIndex)("ID") = 0 Then ClsTickets_Obj.DBInsert() Else ClsTickets_Obj.DBUpdate(ID) End If GridView1.EditIndex = -1 BindGridView("ReSelect") End Sub i'm tryin to edit the data and update it..bt as soon as i click on update,this error comes out.. error- Input string was not in a correct format. Line 65: ClsTickets_Obj.DBUpdate(ID) |
|
#8
|
||||
|
||||
|
hi
i have some doubt over this code. ClsTickets_Obj.DBUpdate(ID) can u tell me what value u are getting for ID variable? i m not able to see in your code where u are setting value for ID ? Hope it make some sense.
__________________
Nothing is Impossible bcoz IMPOSSIBLE itself says.. I M POSSIBLE........................ Be cool !!!!!!!!
|
|
#9
|
|||
|
|||
|
Hello..i need some help on how to do this row data bound thingy..
Objective - to generate an email for the user after they hav created a ticket on their prob.. i'm able to display all the tickets but i wanna display only the informatin of that specific user. hw do i do this?? any help much appreciated(: thx!(: |
|
#10
|
|||
|
|||
|
hello Guddu,(:
its ok wid dat prob..i've solved it..(: can u help me wid dat recent prob of mine?hw do i start abt doin dat?? |
![]() |
| Viewing: ASP Free Forums > Programming > .NET Development > Convert string into SQL datetime value |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|