Not quite sure what I am doing wrong here. I have a string from a text box which is a date (22/10/2013) and I want to use it to select a value from a SQL DB using a stored procedure.
The VB code is:
'gets the values for the daily prices from DB if they exist.
Using conn As New SqlConnection(ConfigurationManager.ConnectionStrings("Optimiser_TestConnectionString").ConnectionString)
conn.Open()
Using cmd As SqlCommand = conn.CreateCommand
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "get_dailypricing"
cmd.Parameters.Add("@datedisplay", SqlDbType.DateTime).Value = date_select.Text
Dim sqlrd As SqlDataReader = cmd.ExecuteReader
If sqlrd.HasRows Then
sqlrd.Read()
Me.date_select.Text = sqlrd.Item("price")
Else
Me.date_select.Text = "N/A"
End If
End Using
End Using
The stored procedure is :
ALTER procedure [dbo].[get_dailypricing]
@DateDisplay date
AS
Begin
select price
from dailyPricing
where dateSubmitted = @DateDisplay
end
I am using Visual Studio 2012 and SQL Server 2012. The date in SQL Server is of type datetime
in the format of 2013-10-22 11:37:49.727
I get an error
The string was not recognized as a valid DateTime. There is an unknown word starting at index 0