Click here to Skip to main content
15,888,068 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hello friends please help me...here is my code .....
private void dateTimePicker1_Leave(object sender, EventArgs e)
{
SqlConnection con = Conn.getopenedconnection();

SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
DateTime date1 = Convert.ToDateTime(dateTimePicker1.Text);
string date11 = date1.ToShortDateString();
//cmd.CommandText = ("SELECT itemcode,maturity FROM SAUDAMAST WHERE COMPCODE='" + Compcls.Gcomp_cd + "'and itemcode='"+comboBox1.SelectedValue+"' and maturity='"+date11+"'");
cmd.CommandText = ("SELECT itemcode,maturity FROM SAUDAMAST WHERE COMPCODE=@COMPCODE and itemcode=@itemcode and maturity=@maturity");
cmd.Parameters.AddWithValue("@COMPCODE", Compcls.Gcomp_cd);
cmd.Parameters.AddWithValue("@itemcode", comboBox1.SelectedValue);
cmd.Parameters.AddWithValue("@maturity", date11);
SqlDataReader sdr = cmd.ExecuteReader();
int count = 0;
while (sdr.Read())//HERE I GET ERROR=Arithmetic overflow error converting expression to data type smalldatetime.
{
count = 1;
}

if (count > 0)
{


MessageBox.Show("Sauda already exists this comodity and this date");
dateTimePicker1.Focus();
// textBox3.Text = "";
}
}
ERROR=Arithmetic overflow error converting expression to data type smalldatetime.
Posted

1 solution

DateTime date1 = Convert.ToDateTime(dateTimePicker1.Text)

statement is getting error

Declare like this

DateTime date1=new datetime();

date1=dateTimePicker1.value


This will solve your problem
 
Share this answer
 
Comments
[no name] 24-Dec-11 6:13am    
thank you very much.....if u don't mind can u tell me reason behind problem
Sridhar Patnayak 24-Dec-11 6:21am    
Datetime is a constructor, so first you have to create object it and pass parameters .
2nd one datetimepicker1.value return date

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900