DateTimePicker

G

Guest

I am using Visual Studio .Net, C#, SQL Server and WinForms with textboxes.
My problem is when I try to insert the date into the sql database I get the
message "the input string was not in the correct format" (06/07/2005) The
database format is "DateTime (8)" how can I fix this problem??? Please help!
The format of the input is this.

dateTimePicker1.Format = DateTimePickerFormat.Custom;
dateTimePicker1.CustomFormat = "MM/dd/yyyy";
txtServiceDate.Text = dateTimePicker1.Text;
 
W

William \(Bill\) Vaughn

Let's see the code that sends this date value to the database.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
www.sqlreportingservices.net
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
 
G

Guest

Thank you this is the insert code.

private void Save_Click(object sender, System.EventArgs e)
{
//
// sqlInsertCommand1

int rsIdentity;

SqlCommand cmdGetIdentity = new SqlCommand();
SqlConnection conn = null;
SqlDataReader rdr = null;

try
{
conn = new SqlConnection("Server=icc-server;DataBase=kennel;Integrated
Security=SSPI");
if (sqlConnection1.State != ConnectionState.Open)
{
conn.Open();
}

SqlCommand cmd = new SqlCommand("InsertCommandTask", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@service_nmb_1",
Convert.ToInt32(txtServiceNumber.Text)));
cmd.Parameters.Add(new SqlParameter("@service_order_task_2",
Convert.ToInt64(txtServiceOrderTask.Text)));
cmd.Parameters.Add(new SqlParameter("@service_code_3",
Convert.ToInt32(txtServiceCode.Text)));
cmd.Parameters.Add(new SqlParameter("@service_date_4",
Convert.ToInt32(txtServiceDate.Text)));
cmd.Parameters.Add(new SqlParameter("@service_time_5",
Convert.ToInt32(txtSerTime.Text)));
cmd.Parameters.Add(new SqlParameter("@animal_id_6",
Convert.ToInt32(txtAnimalId.Text)));
cmd.Parameters.Add(new SqlParameter("@owner_id_7",
Convert.ToInt32(txtOwnerId.Text)));
cmd.Parameters.Add(new SqlParameter("@animal_size_ind_8",
Convert.ToInt32(cbAnimalSize.Text)));
cmd.Parameters.Add(new SqlParameter("@service_description_9",
Convert.ToInt32(txtServiceDesc.Text)));
cmd.Parameters.Add(new SqlParameter("@cost_10",
Convert.ToInt32(txtServiceCost.Text)));

rdr = cmd.ExecuteReader();
if (rdr.Read())
{
MessageBox.Show("Insert Complete. [services] " + conn +
" Successful.","");
}
 
W

William \(Bill\) Vaughn

If the stored procedure parameter is DataTime, the Parameter needs to be
typed as DateTime--not an integer.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
www.sqlreportingservices.net
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________


nbohana said:
Thank you this is the insert code.

private void Save_Click(object sender, System.EventArgs e)
{
//
// sqlInsertCommand1

int rsIdentity;

SqlCommand cmdGetIdentity = new SqlCommand();
SqlConnection conn = null;
SqlDataReader rdr = null;

try
{
conn = new SqlConnection("Server=icc-server;DataBase=kennel;Integrated
Security=SSPI");
if (sqlConnection1.State != ConnectionState.Open)
{
conn.Open();
}

SqlCommand cmd = new SqlCommand("InsertCommandTask", conn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@service_nmb_1",
Convert.ToInt32(txtServiceNumber.Text)));
cmd.Parameters.Add(new SqlParameter("@service_order_task_2",
Convert.ToInt64(txtServiceOrderTask.Text)));
cmd.Parameters.Add(new SqlParameter("@service_code_3",
Convert.ToInt32(txtServiceCode.Text)));
cmd.Parameters.Add(new SqlParameter("@service_date_4",
Convert.ToInt32(txtServiceDate.Text)));
cmd.Parameters.Add(new SqlParameter("@service_time_5",
Convert.ToInt32(txtSerTime.Text)));
cmd.Parameters.Add(new SqlParameter("@animal_id_6",
Convert.ToInt32(txtAnimalId.Text)));
cmd.Parameters.Add(new SqlParameter("@owner_id_7",
Convert.ToInt32(txtOwnerId.Text)));
cmd.Parameters.Add(new SqlParameter("@animal_size_ind_8",
Convert.ToInt32(cbAnimalSize.Text)));
cmd.Parameters.Add(new SqlParameter("@service_description_9",
Convert.ToInt32(txtServiceDesc.Text)));
cmd.Parameters.Add(new SqlParameter("@cost_10",
Convert.ToInt32(txtServiceCost.Text)));

rdr = cmd.ExecuteReader();
if (rdr.Read())
{
MessageBox.Show("Insert Complete. [services] " + conn +
" Successful.","");
}


William (Bill) Vaughn said:
Let's see the code that sends this date value to the database.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
www.betav.com/blog/billva
www.betav.com
www.sqlreportingservices.net
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no
rights.
__________________________________
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top