将表达式转换为数据类型smalldatetime的算术溢出错误. [英] Arithmetic overflow error converting expression to data type smalldatetime.

查看:121
本文介绍了将表达式转换为数据类型smalldatetime的算术溢出错误.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友您好,请帮我...这是我的代码.....
private void dateTimePicker1_Leave(对象发送者,EventArgs e)
{
SqlConnection con = Conn.getopenedconnection();

SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.Connection = con;
DateTime date1 = Convert.ToDateTime(dateTimePicker1.Text);
字符串date11 = date1.ToShortDateString();
//cmd.CommandText =(选择项目代码,成熟度从SAUDAMAST WHERE COMPCODE ="" + Compcls.Gcomp_cd +''和itemcode =""+ comboBox1.SelectedValue +"和成熟度=""+ date11 +" "");
cmd.CommandText =(选择商品代码,成熟度来自SAUDAMAST WHERE COMPCODE = @ COMPCODE和itemcode = @ itemcode且成熟度= @ 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 GET ERROR =将表达式转换为数据类型smalldatetime的算术溢出错误.
{
count = 1;
}

如果(计数> 0)
{


MessageBox.Show("Sauda已经存在这个商品和这个日期");
dateTimePicker1.Focus();
//textBox3.Text =";
}
}
ERROR =将表达式转换为数据类型smalldatetime的算术溢出错误.

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.

推荐答案

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


这篇关于将表达式转换为数据类型smalldatetime的算术溢出错误.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆