Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datetime format using SQL Stored Prodeure

Status
Not open for further replies.

nakkii

Programmer
Jul 11, 2002
38
0
0
US
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
 
Nevermind <:-/

You must make sure your SQL SP Parameter names are exactly the same the in C# code when using SQLClient, DUH!

My problem was "ItemReminder" should have been "Task Reminder"




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
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top