当前位置:编程学习 > C#/ASP.NET >>

一个很奇怪的语句出错信息,请高手帮忙!!

1."将截断字符串或二进制数据,语句已结束"
2."从char数据类型到datetime数据类型的转换导致datetime值越界,语句已终止"
----哪里会有从char到datetime的转换啊?

数据库:
users_id  bigint 8
username nvarchar  20
sex char 10
hometown nvarchar  50
nation char 10
birth datetime 8
health char 10 允许为空
marry nvarchar 50  允许为空
political nvarchar 50 允许为空
address nvarchar 50 允许为空
mobilephone nvarchar 12 允许为空
homephone nvarchar 12 允许为空
email nvarchar 12 允许为空
gra_school nvarchar 50 允许为空
zhuanye nvarchar 50 允许为空
xueli nvarchar 50 允许为空
gra_time datetime 8 允许为空
work_time datetime 8 允许为空
PicUrl image 16 允许为空
dep_id char 10
...

private void addperson_Click(object sender, System.EventArgs e)
{
  if (myFile.PostedFile.ContentLength != 0)
  {
   if (myFile.PostedFile != null)
   {
string nam = myFile.PostedFile.FileName;
int i = nam.LastIndexOf(".");
newext = nam.Substring(i);
DateTime now = DateTime.Now;
newname = now.DayOfYear.ToString() + myFile.PostedFile.ContentLength.ToString();
filename = "\\" + newname + newext;
myFile.PostedFile.SaveAs(Server.MapPath(Request.ApplicationPath) + "\\pic" + filename);
url="\\pic" + filename;
   }
}
string strsql;
strsql="insert into users(username,sex,hometown,nation,birth,health,marry,political,address,mobilephone,homephone,email,gra_school,zhuanye,xueli,gra_time,work_time,dep_id,zhiwu,type,constract_time,cancel_time,PicUrl) values(";
strsql+="'" + username.Text + "',";
strsql+="'" + sex.SelectedValue + "',";
strsql+="'" + hometown.Text + "',";
strsql+="'" + nation.Text + "',";
strsql+="'" + birth.Text + "',";
strsql+="'" + health.Text + "',";
strsql+="'" + marry.SelectedValue + "',";
strsql+="'" + political.Text + "',";
strsql+="'" + address.Text + "',";
strsql+="'" + mobilephone.Text + "',";
strsql+="'" + homephone.Text + "',";
strsql+="'" + email.Text + "',";
strsql+="'" + gra_school.Text + "',";
strsql+="'" + zhuanye.Text + "',";
strsql+="'" + xueli.SelectedValue + "',";
strsql+="'" + gra_time.Text + "',";
strsql+="'" + work_time.Text + "',";
strsql+="'" + dep_name.SelectedValue + "',";
strsql+="'" + zhiwu.Text + "',";
strsql+="'" + type.SelectedValue + "',";
strsql+="'" + constract_time.Text + "',";
strsql+="'" + cancel_time.Text + "',";
strsql+="'" + url + "')"; 

com=new SqlCommand(strsql,conn);
conn.Open();
com.ExecuteNonQuery();
conn.Close();
Response.Write("<script>javascript:alert('添加成功!!!');window.location='default.aspx'</script>");
}



补充:.NET技术 ,  ASP.NET
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,