asp.net excel表数据批量导入sql数据库数据类型为decimal,提示数据类型不正确
if(FileUpload1.HasFile==false)//HasFile用来检查FileUpload是否有指定文件else{for(inti=0;i<dr.Leng...
if (FileUpload1.HasFile == false)//HasFile用来检查FileUpload是否有指定文件
else
{
for (int i = 0; i < dr.Length; i++)
{
string sfzID = dr[i]["身份证号"].ToString();
string xsname = dr[i]["姓名"].ToString();
string xuehao = dr[i]["学号"].ToString();
string banji = dr[i]["班级"].ToString();
string xibie = dr[i]["系别"].ToString();
string zhuanye = dr[i]["专业"].ToString();
string xxoursename = dr[i]["选修课名称"].ToString();
string xxcourseID = dr[i]["选修课编号"].ToString();
string renshu1 = dr[i]["人数"].ToString();
string xueqi = dr[i]["学期"].ToString();
string nianfen = dr[i]["年份"].ToString();
string chengji = dr[i]["成绩"].ToString();
string xuefen = dr[i]["学分"].ToString();
string sqlcheck = "select count(*) from sbxxcourse where xuehao='"+xuehao+"' and xxoursename='" + xxoursename + "'and xueqi='" + xueqi + "' and nianfen='" + nianfen + "' ";
DataBase DB1 = new DataBase();
int count = DB1.RunStr(sqlcheck);
if (count < 1)
{
DataBase DB = new DataBase();
string insertstr = "insert into sbxxcourse(sfzID,xsname,xuehao,banji,xibie,zhuanye,xxoursename,xxcourseID,renshu1,xueqi,nianfen,chengji,xuefen) values('" + sfzID + "','" + xsname + "','" + xuehao + "','" + banji + "','" + xibie + "','" + zhuanye + "','" + xxoursename + "','" + xxcourseID + "',"+int.Parse(renshu1)+",'"+xueqi+"','"+nianfen+"','"+chengji+"',"+Convert.ToDecimal(xuefen)+")";
int count1 = DB.Insert(insertstr);
}
}
}
}
}
数据库里:xeufen字段类型为 decimal,在insert 语句里将convert.Todecimal(xeufen),调试还提示数据类型不正确 展开
else
{
for (int i = 0; i < dr.Length; i++)
{
string sfzID = dr[i]["身份证号"].ToString();
string xsname = dr[i]["姓名"].ToString();
string xuehao = dr[i]["学号"].ToString();
string banji = dr[i]["班级"].ToString();
string xibie = dr[i]["系别"].ToString();
string zhuanye = dr[i]["专业"].ToString();
string xxoursename = dr[i]["选修课名称"].ToString();
string xxcourseID = dr[i]["选修课编号"].ToString();
string renshu1 = dr[i]["人数"].ToString();
string xueqi = dr[i]["学期"].ToString();
string nianfen = dr[i]["年份"].ToString();
string chengji = dr[i]["成绩"].ToString();
string xuefen = dr[i]["学分"].ToString();
string sqlcheck = "select count(*) from sbxxcourse where xuehao='"+xuehao+"' and xxoursename='" + xxoursename + "'and xueqi='" + xueqi + "' and nianfen='" + nianfen + "' ";
DataBase DB1 = new DataBase();
int count = DB1.RunStr(sqlcheck);
if (count < 1)
{
DataBase DB = new DataBase();
string insertstr = "insert into sbxxcourse(sfzID,xsname,xuehao,banji,xibie,zhuanye,xxoursename,xxcourseID,renshu1,xueqi,nianfen,chengji,xuefen) values('" + sfzID + "','" + xsname + "','" + xuehao + "','" + banji + "','" + xibie + "','" + zhuanye + "','" + xxoursename + "','" + xxcourseID + "',"+int.Parse(renshu1)+",'"+xueqi+"','"+nianfen+"','"+chengji+"',"+Convert.ToDecimal(xuefen)+")";
int count1 = DB.Insert(insertstr);
}
}
}
}
}
数据库里:xeufen字段类型为 decimal,在insert 语句里将convert.Todecimal(xeufen),调试还提示数据类型不正确 展开
展开全部
int.Parse(renshu1)
Convert.ToDecimal(xuefen)
字符串拼接,不用转类型了
Convert.ToDecimal(xuefen)
字符串拼接,不用转类型了
追问
能说的详细点吗?不明白(字符串拼接,不用转类型了)
追答
string insertstr = "insert into sbxxcourse(sfzID,xsname,xuehao,banji,xibie,zhuanye,xxoursename,xxcourseID,renshu1,xueqi,nianfen,chengji,xuefen) values('" + sfzID + "','" + xsname + "','" + xuehao + "','" + banji + "','" + xibie + "','" + zhuanye + "','" + xxoursename + "','" + xxcourseID + "',"+renshu1+",'"+xueqi+"','"+nianfen+"','"+chengji+"',"+xuefen+")";
改成这样
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询