0

I have a web page in which there is a textbox that asks my users to enter a start date. What I'm trying to do from there is that no matter what the end date is, my page will calculated that from the text box, store it as a variable and pass it to my stored procedure. Here is the page I have so far:

Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles wasoncallButton.Click
        Dim ds As New DataSet
        Dim dt As New DataTable
        Dim da As New SqlDataAdapter
        Dim cmd As New SqlCommand
        Dim newDate As DateTime
        Dim connectionString As String = "Initial Catalog=mdr;Data Source=xxxxx;uid=xxxxx;password=xxxxx"
        Dim con As New SqlConnection(connectionString)
        con.Open()
        cmd.Connection = con
        cmd.CommandType = CommandType.StoredProcedure
        cmd.CommandText = "sp_owncalls3"
        cmd.Parameters.AddWithValue("@start", dateTextBox.Text)


        Try
            If newDate.Date.AddDays(1).AddSeconds(-1).ToString() Then
                cmd.Parameters.AddWithValue("@dayend", newDate)
            Else
                errorlabel.Text = "Invalid Date"
            End If
        Catch ex As Exception
            Response.Write("Error:" & ex.ToString)
        End Try
    End Sub


End Class

The two variables here are @start and @dayend. @start will be gathered from the text box, but I need to know how to calculate and save the variable for @dayend. Any help would be appreciated.

Thank you,

Doug

3
Contributors
4
Replies
5
Views
6 Years
Discussion Span
Last Post by cvplay
0

I don't get it. Do you have one textbox for @start and one for @dayend?
@Dayend is a number or a date?

I don't have a textbox for @dayend, what I want to do is calculate the day end based on the values that the user types in the textbox for @start. @Dayend is a date/time.

0

You're already calculating @dayend

newDate.Date.AddDays(1).AddSeconds(-1).ToString()

I don't understand why you have an "If" in the front of it though?!

The way I would do it would be:

Try
cmd.Parameters.AddWithValue("@dayend", newDate.Date.AddDays(1).AddSeconds(-1).ToString("yyyy-MM-dd HH:mm:ss.fff"))
cmd.ExecuteNonQuery()
Catch ex As Exception
errorlabel.Text = "Invalid Date"
End Try

I hope that helps...


- Looking for a new job? Computer Jobs

Edited by cvplay: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.