Hi,
I'm trying to write my first vb.net program to update a date/time field in a SQL database. I'm trying to update the table by using passing a date parameter to a stored procedue and then run the stored procedure to update my table. I'm receiving the following error message:
Next, my vb.net code to run the procedure:
Any help would be greatly appreciated.
I'm trying to write my first vb.net program to update a date/time field in a SQL database. I'm trying to update the table by using passing a date parameter to a stored procedue and then run the stored procedure to update my table. I'm receiving the following error message:
First, my stored procedure is as follows:An Unhandled exception of type 'System.Data.SqlClient.SQLException occured in System.data.dll'
VB.NET:
CREATE PROCEDURE [dbo].[UpdateProcRunTracker] (
@ProcessDate as datetime)
AS
UPDATE Run_Tracker SET
Process_date = @Processdate
GO
VB.NET:
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] cmmRunTracker [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] SqlCommand[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] ws_date2 [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2][COLOR=#0000ff]Date[/COLOR][/SIZE][SIZE=2] = DateTimePicker1.Value[/SIZE]
[SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] parameter [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] SqlParameter[/SIZE]
[SIZE=2]cnnRunTracker = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlConnection[/SIZE]
[SIZE=2]cnnRunTracker.ConnectionString = "server=xxxxxxxx;database=" + List1.SelectedItem + ";UID=xxxxxxxx;password=xxxxxxxx;"[/SIZE]
[SIZE=2][COLOR=#008000]'Open the conncection[/COLOR][/SIZE]
[SIZE=2]cnnRunTracker.Open()[/SIZE]
[SIZE=2]cmmStoredProcedure = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlCommand("UpdateProcRunTracker", cnnRunTracker)[/SIZE]
[SIZE=2]cmmStoredProcedure.CommandType = CommandType.StoredProcedure[/SIZE]
[SIZE=2]' set parameter[/SIZE]
[SIZE=2]Parameter = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlParameter("@process_date", SqlDbType.DateTime, 8)[/SIZE]
[SIZE=2]parameter.Value = ws_date2 [/SIZE][SIZE=2][COLOR=#008000]'Value of the parameter[/COLOR][/SIZE]
[SIZE=2]Parameter.Direction = ParameterDirection.Output[/SIZE]
[SIZE=2]cmmStoredProcedure.Parameters.Add(Parameter)[/SIZE]
[SIZE=2]cmmStoredProcedure.ExecuteNonQuery()[/SIZE]
[SIZE=2]cnnRunTracker.Close()[/SIZE]
Last edited by a moderator: