sql c# 出现错误字符串向时间转换失败!!
stringsql=string.Format("select*fromcertificateManagewherecertificateNo='{0}'orperson...
string sql = string.Format("select * from certificateManage where certificateNo ='{0}'or personName = '{1}' or startCertificateDate ='convert(varchar(12) , {2}, 111 )' or" +
" levelName = '{3}' or healthlevelName = '{4}' or categoryProtectName = '{5}'",CFManage.CertificateNo,CFManage.PersonName,CFManage.StartCertificateDate,CFManage.LevelName,CFManage.HealthlevelName,CFManage.CategoryProtectName); 展开
" levelName = '{3}' or healthlevelName = '{4}' or categoryProtectName = '{5}'",CFManage.CertificateNo,CFManage.PersonName,CFManage.StartCertificateDate,CFManage.LevelName,CFManage.HealthlevelName,CFManage.CategoryProtectName); 展开
2个回答
展开全部
单引号内的convert只会当做字符串来处理,而不是函数。
做如下修改:
string sql = string.Format("select * from certificateManage where certificateNo ='{0}'or personName = '{1}' or startCertificateDate ='{2}' or" +
" levelName = '{3}' or healthlevelName = '{4}' or categoryProtectName = '{5}'",CFManage.CertificateNo,CFManage.PersonName,CFManage.StartCertificateDate.ToString("yyyy-MM-dd"),CFManage.LevelName,CFManage.HealthlevelName,CFManage.CategoryProtectName);
做如下修改:
string sql = string.Format("select * from certificateManage where certificateNo ='{0}'or personName = '{1}' or startCertificateDate ='{2}' or" +
" levelName = '{3}' or healthlevelName = '{4}' or categoryProtectName = '{5}'",CFManage.CertificateNo,CFManage.PersonName,CFManage.StartCertificateDate.ToString("yyyy-MM-dd"),CFManage.LevelName,CFManage.HealthlevelName,CFManage.CategoryProtectName);
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询