I have a parameterized SQL Stored Procedure that performs an insert in SQL, when I try to the date I am getting and error:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll
Additional information: System error.
If I comment out the lines for the two dates everything runs fine.
What am I missing? Here is my code:
SqlConnection MyConn = new SqlConnection
("Data Source=SQLServer;integrated Security=sspi;" +
"initial catalog=MyDB;");
SqlCommand AddCMD = new SqlCommand
("ap_MiscAdd", MyConn);
AddCMD.CommandType = CommandType.StoredProcedure;
SqlParameter RetVal = AddCMD.Parameters.Add
("RetVal", SqlDbType.Int);
RetVal.Direction = ParameterDirection.ReturnValue;
SqlParameter Owner = AddCMD.Parameters.Add
("@ItemOwner", SqlDbType.Int);
Owner.Direction = ParameterDirection.Input;
SqlParameter PlanRefNum = AddCMD.Parameters.Add
("@ItemPlanRefNum", SqlDbType.Int);
PlanRefNum.Direction = ParameterDirection.Input;
SqlParameter PlanName = AddCMD.Parameters.Add
("@ItemPlanName", SqlDbType.VarChar, 140);
PlanName.Direction = ParameterDirection.Input;
SqlParameter Desc = AddCMD.Parameters.Add
("@ItemDesc", SqlDbType.NText, 1073741823);
Desc.Direction = ParameterDirection.Input;
//SqlParameter Priority = AddCMD.Parameters.Add
// ("@ItemPriority", SqlDbType.Int);
//Priority.Direction = ParameterDirection.Input;
SqlParameter Reminder = AddCMD.Parameters.Add
("@ItemReminderDate", SqlDbType.DateTime);
Reminder.Direction = ParameterDirection.Input;
SqlParameter DueDate = AddCMD.Parameters.Add
("@ItemDueDate", SqlDbType.DateTime);
DueDate.Direction = ParameterDirection.Input;
Owner.Value = cboAdmin.SelectedValue;
PlanRefNum.Value = cboPlanRefNum.SelectedValue;
PlanName.Value = cboPlanName.SelectedValue;
Desc.Value = txtDescription.Text;
//Priority.Value = null;
Reminder.Value = dtpReminder.Value;
DueDate.Value = dtpDueDate.Value;
MyConn.Open();
//strRowAffect = AddCMD.ExecuteNonQuery().ToString() ;
//AddCMD.ExecuteNonQuery().ToString() ;
AddCMD.ExecuteNonQuery() ;
//Console.WriteLine("Number of Rows: " + strRowAffect );
//Console.WriteLine("Return Value: " + RetVal.Value);
Persistence....Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination alone are omnipotent. -Calvin Coolidge
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll
Additional information: System error.
If I comment out the lines for the two dates everything runs fine.
What am I missing? Here is my code:
SqlConnection MyConn = new SqlConnection
("Data Source=SQLServer;integrated Security=sspi;" +
"initial catalog=MyDB;");
SqlCommand AddCMD = new SqlCommand
("ap_MiscAdd", MyConn);
AddCMD.CommandType = CommandType.StoredProcedure;
SqlParameter RetVal = AddCMD.Parameters.Add
("RetVal", SqlDbType.Int);
RetVal.Direction = ParameterDirection.ReturnValue;
SqlParameter Owner = AddCMD.Parameters.Add
("@ItemOwner", SqlDbType.Int);
Owner.Direction = ParameterDirection.Input;
SqlParameter PlanRefNum = AddCMD.Parameters.Add
("@ItemPlanRefNum", SqlDbType.Int);
PlanRefNum.Direction = ParameterDirection.Input;
SqlParameter PlanName = AddCMD.Parameters.Add
("@ItemPlanName", SqlDbType.VarChar, 140);
PlanName.Direction = ParameterDirection.Input;
SqlParameter Desc = AddCMD.Parameters.Add
("@ItemDesc", SqlDbType.NText, 1073741823);
Desc.Direction = ParameterDirection.Input;
//SqlParameter Priority = AddCMD.Parameters.Add
// ("@ItemPriority", SqlDbType.Int);
//Priority.Direction = ParameterDirection.Input;
SqlParameter Reminder = AddCMD.Parameters.Add
("@ItemReminderDate", SqlDbType.DateTime);
Reminder.Direction = ParameterDirection.Input;
SqlParameter DueDate = AddCMD.Parameters.Add
("@ItemDueDate", SqlDbType.DateTime);
DueDate.Direction = ParameterDirection.Input;
Owner.Value = cboAdmin.SelectedValue;
PlanRefNum.Value = cboPlanRefNum.SelectedValue;
PlanName.Value = cboPlanName.SelectedValue;
Desc.Value = txtDescription.Text;
//Priority.Value = null;
Reminder.Value = dtpReminder.Value;
DueDate.Value = dtpDueDate.Value;
MyConn.Open();
//strRowAffect = AddCMD.ExecuteNonQuery().ToString() ;
//AddCMD.ExecuteNonQuery().ToString() ;
AddCMD.ExecuteNonQuery() ;
//Console.WriteLine("Number of Rows: " + strRowAffect );
//Console.WriteLine("Return Value: " + RetVal.Value);
Persistence....Nothing in the world can take the place of persistence. Talent will not; nothing is more common than unsuccessful men with talent. Genius will not; unrewarded genius is almost a proverb. Education will not; the world is full of educated derelicts. Persistence and determination alone are omnipotent. -Calvin Coolidge