Qt Qdate写入sql server报错:从字符串转换日期和/或时间时,转换失败。

本人小白一个,做学校布置的大作业时遇到这样一个问题:

 query.prepare("INSERT INTO Orders(Name,Quantity,Weight,G_Type,Destination,Applicant,S_Date)"
                      "VALUES(:name,:quantity,:weight,:type,:destination,:applicant,:date)");
        query.bindValue(":name",ui->NameEdit->text());
        query.bindValue(":quantity",ui->quanEdit->value());
        query.bindValue(":weight",ui->WeigEdit->value());
        query.bindValue(":type",ui->TypeEdit->text());
        query.bindValue(":destination",ui->DestinEdit->text());
        query.bindValue(":applicant",Applicant);
        query.bindValue(":date",QDate::currentDate().toString("yyyy-mm-dd"));

        query.exec();

结果报错:QODBCResult::exec: Unable to execute statement: "[Microsoft][ODBC SQL Server Driver][SQL Server]从字符串转换日期和/或时间时,转换失败。"
实在不知道该怎么办,求大神解答。

0

1个回答

toString("yyyy-mm-dd") 月份是大写的MM表示,QDate::currentDate().toString("yyyy-mm-dd")你这样得到的字符串是"2016-mm-02"
会不会是你传过去的字符串不是日期字符串所以报的这个错。

0
CrazyKeyboardMan
数据刘 的确是我没有把MM大写。
2 年多之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
从字符串转换日期和/或时间时,转换失败。sql
语句是这样的:rnALTER proc [dbo].[yuebao]rnrn@FYear int,rn@fperiod intrnrnasrnset nocount onrnrncreate table #tbrn( id int,rnid1 int,rnLX VARCHAR(255),rnFEndBalance1 decimal(18,2),rnFEndBalance2 decimal(18,2)rn)rninsert #tb(lx,id,id1,FEndBalance1)rnSELECT '1.1成都片区项目',1,1,B.FAmountIncludeTaxFor FROM t_RPContract Arninner JOIN t_rpContractEntry B ON A.FContractID=B.FContractIDrn WHERE A.FBase='258' rnAND DATENAME(YEAR,A.FDate)=@FYearrnAND DATENAME(MONTH,A.FDate)=@fperiodrnrninsert #tb(lx,id,id1,FEndBalance2)rnSELECT '1.1成都片区项目',1,2,B.FAmountIncludeTaxFor FROM t_RPContract Arninner JOIN t_rpContractEntry B ON A.FContractID=B.FContractIDrn WHERE A.FBase='258' rnAND A.FDate<=dateadd(day,-1,dateadd(month,1,cast(cast(@FYear as CHAR(4))+'-'+CAST(@fperiod as CHAR(2))+'-1' as DATE)))
从字符串转换日期和/或时间时,转换失败。
private void btAdd_Click(object sender, System.EventArgs e)n n if (textName.Text.Trim()==""||textWriter.Text.Trim()==""||textNum.Text.Trim()=="")n MessageBox.Show("请填写完整信息","提示");n elsen n oleConnection1.Open();n string sql = "update book set BName='"+textName.Text.Trim()+"',BWriter='"+textWriter.Text.Trim()+"',BPublish='"+textPublish.Text.Trim()+"',"+ n "BDate='" + date1.Text.Trim() + "',BNum='"+textNum.Text.Trim()+"',BPrice='"+textPrice.Text.Trim()+"',BRemark='"+textRemark.Text.Trim()+"'"+n " where BID='"+textID.Text.Trim()+"'";n SqlCommand cmd = new SqlCommand(sql,oleConnection1);n cmd.ExecuteNonQuery();n MessageBox.Show("修改成功","提示");n this.Close();n oleConnection1.Close();n n
C# 出现“从字符串转换日期和/或时间时 转换失败”
[img=https://img-bbs.csdn.net/upload/201511/25/1448451318_984816.jpg][/img]rnrnrnbutton的代码:rn private void button1_Click(object sender, EventArgs e)rn rn if (IsValidataInput())rn rnrn string sql = String.Format(@"insert into kaoqin(清洁工号, 出勤状态, 提交日期) values(0,'1','2')"rn , Convert.ToInt32(comboBox1.Text), comboBox2.Text,dateTimePicker1.Text);rnrn tryrn rn SqlCommand command = new SqlCommand(sql, DBHelper.connection);rn DBHelper.connection.Open();rnrn int result = command.ExecuteNonQuery();rnrn if (result == 1)rn rn MessageBox.Show("录入信息成功!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);rn rn elsern rn MessageBox.Show("录入信息失败!", "操作提示", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);rn rn rn catch (Exception ex)rn rn MessageBox.Show(ex.Message);rn rnrn finallyrn rn DBHelper.connection.Close();rnrn rnrn
从字符串转换日期和/或时间时,转换失败
public partial class Default2 : System.Web.UI.Pagernrn string M_Str_mindate;rn string M_Str_maxdate;rn protected void Page_Load(object sender, EventArgs e)rn rn //显示统计时间rn labCountDate.Text = DateTime.Now.ToString();rn //本日访问人数的计算rn M_Str_mindate = DateTime.Now.ToShortDateString() + " 0:00:00";rn M_Str_maxdate = DateTime.Now.AddDays(1).ToShortDateString() + " 0:00:00";rn DataSet ds = DB.reDs("select * from tb_CounterInfo where LoginTime>='" + M_Str_mindate + "'and LoginTime<'" + M_Str_maxdate + "'");rn labCountDay.Text = ds.Tables[0].Rows.Count.ToString();rn rnrn[img=https://img-bbs.csdn.net/upload/201608/25/1472112927_261605.png][/img]rn数据库的Logintime是datetime类型的
VS2012 从字符串转换日期和/或时间时,转换失败
修改系统时间显示格式就行了
老是提示从字符串转换日期和/或时间时,转换失败。
declare @sql varchar(8000)rnset @sql = 'select [仓库],[仓库名称],[品号] 'rnselect @sql = @sql + ' , max(case CA09 when ''' + CA09 + ''' then CA082 else 0 end) [' + CA09 + ']'+'需求'+' , max(case CA09 when ''' + CA09 + ''' then CA08 else 0 end) [' + CA09 + ']'+'缺料' rnfrom (select distinct CA09 from AZCALIST where CA09 is not null) as arnset @sql = @sql + ' from #tb2 group by [仓库],[仓库名称],[品号] 'rnrn运行以上代码老是提示如下错误rnrn消息 241,级别 16,状态 1,第 3 行rn从字符串转换日期和/或时间时,转换失败。rnrnCA09列 是日期格式, 但是我已经加了‘’‘ ,请高人帮忙看一下 该如何修正,非常感谢。
错误-从字符串转换日期和/或时间时,转换失败
在敲上机的时候,将用户上机信息插入到Online表中一直出现这个错误,以下时图片和解决办法 1.查看实体的数据类型是否正确(DateTime) 2.查看数据库中的数据类型是否正确(DateTIme) 3.查看Main中是否将string类型的数据转换为Datetime类型 4.数据库插入语句错误 以下是一一对应的正确的代码 1. 2. 3. 4. ...
从字符串转换日期和/或时间时,转换失败。 急
[code=sql] select CONVERT(datetime,rn(CONVERT(varchar(100), DepartureDate,23)+' '+SUBSTRING(DepartureTime,1,2)+rn ':'+SUBSTRING(DepartureTime,3,2))) as ddd fromrn tpTicket rn[/code]rnrnDepartureDate的值是2012-10-18 00:00:00.000rnrnDepartureTime的值是0715rn想转换为时间格式并与当前时间比较 转换的时候报错了;rn消息 241,级别 16,状态 1,第 1 行rn从字符串转换日期和/或时间时,转换失败。
从字符串转换日期和/或时间时 转换失败。
SQL里的数据类型是DATETIME,C#变量类型也是DATETIME。rnSqlCommand的Parameters设置rnAdd("@tm",SqlDbType.DateTime);rnParameters["@tm"].Value = tm();rn两者同样是DATETIME类型,唯一的区别是客户端的时间格式里带有星期如:2013/12/10 星期二 10:55:01rnrn这样转换的时候会出错,rnrn如果告诉我要ToString("yyyy-MM-dd HH:mm:ss.fff"); 这个不是我想要的。
从字符串转换日期和/或时间时,转换失败怎么解决
从字符串转换日期和/或时间时,转换失败。rnrnDescription: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. rnrnException Details: System.Data.SqlClient.SqlException: 从字符串转换日期和/或时间时,转换失败。rnrnSource Error: rnrnAn unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.rnrnStack Trace: rnrnrn[SqlException (0x80131904): 从字符串转换日期和/或时间时,转换失败。]rn System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +404rn System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning() +412rn System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +1363rn System.Data.SqlClient.SqlDataReader.HasMoreRows() +301rn System.Data.SqlClient.SqlDataReader.ReadInternal(Boolean setTimeout) +422rn System.Data.Common.DataAdapter.FillLoadDataRow(SchemaMapping mapping) +167rn System.Data.Common.DataAdapter.FillFromReader(DataSet dataset, DataTable datatable, String srcTable, DataReaderContainer dataReader, Int32 startRecord, Int32 maxRecords, DataColumn parentChapterColumn, Object parentChapterValue) +292rn System.Data.Common.DataAdapter.Fill(DataTable[] dataTables, IDataReader dataReader, Int32 startRecord, Int32 maxRecords) +609rn System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior) +371rn System.Data.Common.DbDataAdapter.Fill(DataTable[] dataTables, Int32 startRecord, Int32 maxRecords, IDbCommand command, CommandBehavior behavior) +504rn System.Data.Common.DbDataAdapter.Fill(DataTable dataTable) +324rn Bzw.Data.DbHelper.ExecuteDataTable(DbCommand cmd) +552rn Bzw.Data.QuerySection`1.ExcuteDataTable(QuerySection`1 query, Boolean all) +583rn Bzw.Web.Ascx.Public.Mune.Page_Load(Object sender, EventArgs e) +381rn System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25rn System.Web.UI.Control.LoadRecursive() +71rn System.Web.UI.Control.LoadRecursive() +190rn System.Web.UI.Control.LoadRecursive() +190rn System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3048rn
asp.net/C#:从字符串转换日期和/或时间时,转换失败。
网页代码在其他人电脑上就可以正常运行,在我的电脑上就报错:从字符串转换日期和/或时间时,转换失败。rn向数据库中插入一条数据,数据库字段为date型,数据来源于日历控件的值,代码为 DateTime day = Calendar1.SelectedDate;rn请教大神是什么原因,同样的代码在其他人的电脑上可以正常运行
字符串转换为日期或时间时,转换失败
用程序调用存储过程时出现标题错误rn但直接exec存储过程时却正常,传的参数是一样的,都是字符串rn为什么呢?
sql中插入语句参数格式&&从字符串转换日期和/或时间时,转换失败
public int insertTdInfo(Td2 td)rn rn StringBuilder sb = new StringBuilder();rn sb.Append("insert into T_appoint (area,week,time,teacher,describtion,state) values('@area','@week','2017/9/12 23:00:00','@teacher','@descrbtion','@state');");//这里是能够执行成功的rn //sb.Append("insert into T_appoint (area,week,time,teacher,describtion,state) values('@area','@week','@time','@teacher','@descrbtion','@state');");//但是改成参数添加的形式就会报错“System.Data.SqlClient.SqlException:“从字符串转换日期和/或时间时,转换失败。”rn SqlParameter[] paras =rn new SqlParameter("@area",td.area),rn new SqlParameter("@week",td.week),rn new SqlParameter("@time",DateTime.Now), //此数据类型也为DateTime rn new SqlParameter("@teacher",td.teacher),rn new SqlParameter("@describtion",td.describtion),rn new SqlParameter("@state",td.state),rnrn ;rn rn return SqlHelper.ExecuteNonQuery(sb.ToString(), CommandType.Text, paras);rn
C#winform sql查询数据库,提示: 从字符串转换日期和/或时间时,转换失败。
DateTime Tmpstart = DateTime.Parse(StartData.Value.ToString("yyyy/MM/dd 0:00:00"));rn DateTime Tmpend = DateTime.Parse(EndData.Value.ToString("yyyy/MM/dd 23:59:59"));rn //string Tmpstart = StartData.Value.ToString();rn // string Tmpend = EndData.Value.ToString();rn string MySelect = "select 租赁时间,租金 from GuiderData where 租赁时间 > 'Tmpstart' and 租赁时间< 'Tmpend' ";rn consql.Open();rn /*SqlCommand sqlcmd = new SqlCommand(MySelect,consql);rn sqlcmd.ExecuteNonQuery();*/rn DataSet ds = new DataSet();rn SqlDataAdapter da = new SqlDataAdapter(MySelect, consql);rn da.Fill(ds);rn RentData.DataSource = ds.Tables[0];
SQL union 从字符串转换日期和/或时间时,转换失败(基础知识不牢固导致坑爹的问题)
今天生成环境出现了一个问题,在使用UNION联合查询两个订单表的时候,老是提示: 从字符串转换日期和/或时间时,转换失败,然后看了一下数据,没有问题啊,所有的时间都是有数据并且格式十分正确。
求助:从字符串转换日期和/或时间时,转换失败。sql语句没问题呀?
[code=csharp]using System;rnusing System.Collections.Generic;rnusing System.ComponentModel;rnusing System.Data;rnusing System.Drawing;rnusing System.Linq;rnusing System.Text;rnusing System.Windows.Forms;rnusing System.Data.SqlClient;rnnamespace 学生成绩管理系统rnrn public partial class StudentMsgFrm : Formrn rn private int current = 1;rn public StudentMsgFrm()rn rn InitializeComponent();rn rn rnrn private void btnYes_Load(object sender, EventArgs e)rn rn rdoMale.Checked = true;//默认学生性别为男rn cboDept.SelectedIndex = 0;//初始选择组合框中的第一项(“计算机系”)rn dtBirthday.MaxDate = DateTime.Now;//设置出生日期的最大值为系统当前时间rn dtBirthday.Value = dtBirthday.MinDate;//设置出生日期默认值为最小值rn timeGo.Enabled = true;//启动计时器rn rnrn private void cboDept_SelectedIndexChanged(object sender, EventArgs e)rn rn switch (cboDept.SelectedIndex)rn case 0:rn lstSpec.Items.Clear();//rn lstSpec.Items.Add("计算机科学与技术");rn lstSpec.Items.Add("信息与计算科学");rn break;rn case 1:rn lstSpec.Items.Clear();rn lstSpec.Items.Add("集成电路与集成系统");rn lstSpec.Items.Add("集成电路设计");rn break;rn case 2:rn lstSpec.Items.Clear();rn lstSpec.Items.Add("通信工程");rn lstSpec.Items.Add("电子信息工程");rn lstSpec.Items.Add("电磁场与无线技术");rn lstSpec.Items.Add("机械制造及自动化");rn break;rn case 3:rn lstSpec.Items.Clear();rn lstSpec.Items.Add("国际经济与贸易");rn lstSpec.Items.Add("电子商务");rn lstSpec.Items.Add("信息管理与信息系统");rn lstSpec.Items.Add("财务管理");rn break;rn default:rn lstSpec.Items.Clear();rn lstSpec.Items.Add("数字动画");rn lstSpec.Items.Add("影视动画");rn lstSpec.Items.Add("商务插画");rn break;rnrnrn rn lstSpec.SelectedIndex = 0;//设置默认专业为第一个选项rn rnrn private void button2_Click(object sender, EventArgs e)rn rn string sex = "";rn if (rdoMale.Checked)rn sex = rdoMale.Text;rn elsern sex =rdoFemale.Text;rn string dept = cboDept.SelectedItem.ToString();rn string spec = lstSpec.SelectedItem.ToString();rnrn string hobby = "";rn if (checkBox1.Checked) hobby += checkBox1.Text;rn if (checkBox2.Checked) hobby +="、"+ checkBox2.Text;rn if (checkBox3.Checked) hobby += "、" + checkBox3.Text;rn if (checkBox4.Checked) hobby += "、" + checkBox4.Text;rn if (checkBox5.Checked) hobby += "、" + checkBox5.Text;rn if (checkBox6.Checked) hobby += "、" + checkBox6.Text;rn string sql = String.Format("INSERT INTO StudentMsg(StudentName,Sex,Birthday,Department,Speciality,Hobby)VALUES('0','1','2','3','4','5')", txtName.Text, sex, dtBirthday.Value, dept, spec, hobby);//sq;语句rn string connString = @"Data Source=Win-01412261307;Initial Catalog=MySchool;Integrated Security=True";rn using (SqlConnection conn = new SqlConnection(connString))rn rn conn.Open();rn SqlCommand comm = new SqlCommand(sql, conn);//创建command对象rn int n = comm.ExecuteNonQuery();//执行“添加”命令,返回值为更新的行数rn rn if (n > 0)rn rn MessageBox.Show("添加学生信息成功", "添加成功", MessageBoxButtons.OK, MessageBoxIcon.Information);rn rn elsern rn MessageBox.Show("添加学生信息失败", "添加失败", MessageBoxButtons.OK, MessageBoxIcon.Information);rn rn rn /*string info = "你的姓名是:" + txtName.Text;rn info += "\n性别为:" + sex;rn info += "\n出生年月为:" + dtBirthday.Value.ToShortDateString();rn info += "\n您是:" + dept+"系"+spec+"专业学生";rn info += "\n你的兴趣有:" + hobby;rnrn MessageBox.Show(info, "学生信息",rn MessageBoxButtons.OK, MessageBoxIcon.Information);rn */rn rnrn private void btnClose_Click(object sender, EventArgs e)rn rn this.Close();rn rnrn private void timeGo_Tick(object sender, EventArgs e)rn rn if (lblTip.Left >= this.Width)rn rn lblTip.Left = 0;rn rn lblTip.Left += 1;rn rnrn rn rnrn[/code]
一模一样的的存储过程,执行出来一个正确一个提示"从字符串转换日期和/或时间时,转换失败"
存储过程1:[code=SQL]createPROCEDURE [dbo].[StorSaleReportDateSet] rn -- Add the parameters for the stored procedure herernrn @StartTime dateTime,rn @EndTime dateTime,rn @flag int = 0 outputrn rnAS rnBEGINrnrnSELECTrnproduct.productCode,rnproduct.productName,rnmax(product.unitName) as unitName,rnSUM(proStorBill.quantity) as StorQuantity,rnSUM(proSaleBill.quantity) as SaleQuantity,rnAVG(product.storQuantity) as remainQuantityrnrnfrom product left join proStorBill on product.productName=proStorBill.productName rn and proStorBill.storDate is not null and proStorBill.storDate<@EndTime and proStorBill.storDate>@StartTimern left join proSaleBill on product.productName=proSaleBill.productNamern and proSaleBill.saleDate is not null and proSaleBill.saleDate<@EndTime and proSaleBill.saleDate>@StartTimern rn where (proStorBill.storDate<@EndTime and proStorBill.storDate>@StartTime) orrn (proSaleBill.saleDate<@EndTime and proSaleBill.saleDate>@StartTime)rn rn group by product.productName,product.productCodernrn if (@@ROWCOUNT>0)rn Set @flag = 1rn elsern Set @flag = 0rnrnEND[/code]rn执行:[code=SQL]exec [StorSaleReportDateSet] '2012/5/27 0:00:00','2012/6/30 0:00:00'[/code]rn结果正确:[img=http://img.my.csdn.net/uploads/201206/26/1340703153_6490.png][/img]rnrn第二个存储过程:rn[code=SQL]create PROCEDURE [dbo].[receivableReportDateSet] rn -- Add the parameters for the stored procedure herern @StartTime dateTime,rn @EndTime dateTime,rn @flag int = 0 outputrn rnAS rnBEGINrnrnSELECTrnbusiPart.busiPartCode,rnbusiPart.busiPartName,rnSUM(proSaleBill.totalPrice) as totalPrice,rnSUM(receiptBill.realReciAmount) as realReciAmount,rnAVG(busiPart.creditUsed) as creditUsedrnrnfrom busiPart left join proSaleBill on busiPart.busiPartName=proSaleBill.BusiName rn and proSaleBill.saleDate is not null and proSaleBill.saleDate<@EndTime and proSaleBill.saleDate>@StartTimern left join receiptBill on busiPart.busiPartName=receiptBill.receDatern and receiptBill.receDate is not null and receiptBill.receDate<@EndTime and receiptBill.receDate>@StartTimern rn where (proSaleBill.saleDate<@EndTime and proSaleBill.saleDate>@StartTime) orrn (receiptBill.receDate<@EndTime and receiptBill.receDate>@StartTime)rn rn group by busiPart.busiPartName,busiPart.busiPartCodernrn if (@@ROWCOUNT>0)rn Set @flag = 1rn elsern Set @flag = 0rnrnEND[/code]rn执行:[code=SQL]exec [receivableReportDateSet] '2012/5/27 0:00:00','2012/6/30 0:00:00'[/code]rn错误提示:[img=http://img.my.csdn.net/uploads/201206/26/1340703272_9205.png][/img]rnrn存储过程几乎是一样的,只是表换了,传的参数也是一模一样。但是一个执行结果正确,另一个却提示“从字符串转换日期和/或时间时,转换失败”。 小弟实在不解,恳请各位大侠解答,万分感谢
求助,从字符串转换日期和/或时间时,转换失败,但结果显示正常
select rncase when LEN(CONVERT(varchar(2),(DATEPART(hh,std)*60+ (DATEPART(mi,std) -30))%60)) = 1rnthen convert(time,(CONVERT(varchar(2), (DATEPART(hh,std)*60+ (DATEPART(mi,std) -30))/60)) + ':0' + convert(varchar(2), (DATEPART(hh,std)*60+ (DATEPART(mi,std) -30))%60))rnelse convert(time,(CONVERT(varchar(2), (DATEPART(hh,std)*60+ (DATEPART(mi,std) -30))/60)) + ':'+ convert(varchar(2), (DATEPART(hh,std)*60+ (DATEPART(mi,std) -30))%60))rnend,* from focData rn提示从字符串转换日期和/或时间时,转换失败,但是结果却是正常的,请问怎么解决
从字符串转换日期和/或时间时,转换失败。datediff函数导致的
[code=sql]select datediff(mi,clockInRecord.fQDSJ,clockInRecord.fQTSJ) as mi,clockInRecord.fKQH rn from dbo.OA_ClockInRecord clockInRecord rn where clockInRecord.fQTSJ<>'' and clockInRecord.fQDSJ <>''[/code]rnrnrnfQDSJ和fQTSJ都是varchar(100),存储的数据格式都是08:25:09这种,但是执行SqlServer就报rnrn消息 241,级别 16,状态 1,第 1 行rn从字符串转换日期和/或时间时,转换失败。rnrn我就是想计算时间差多少分钟,表的数据类型不变,求问大神怎么解决?
对数据库中的时间字段插入值时,老是说从字符串转换日期和/或时间时,转换失败
question.date = DateTime.Parse(DateTime.Now.ToString());rnrndate是数据库中的一个表示时间的字段,类型定义的是DateTime,对他做插入是报出“从字符串转换日期和/或时间时,转换失败”。。。rnrn急!!!!!
大家帮我看个SQL2008字符串转换时间问题。执行提示从字符串转换日期和/或时间时,转换失败。在线等啊!
ALTER proc [dbo].[Sp_tj_Sjtj]rn(rn @Communityid varchar(10),rn @type varchar(5) ,rn @Stime datetime, --开始时间rn @Etime datetime --截止时间rn)rnasrnrnbeginrndeclare @strsql varchar(8000),rn @name varchar(20),rn @where varchar(50)rn if @Communityid='0' or @Communityid='' or @Communityid =null or @Communityid is null rn set @Communityid ='null'rn IF @Stime = ''rnSET @Stime = NULL rn IF @Etime = ''rnSET @Etime = NULLrn if(@type='1')rn beginrn set @name='TypeName'rn set @where='t.Typeid';rn endrn else if(@type='2')rn beginrn set @name='FlowCategoryName'rn set @where='fc.FlowCategoryid';rn endrn elsern beginrn set @name='FlowName'rn set @where='f.Flowid';rn endrn rn rn set @strsql ='rn rn select isnull( '+@name+',''未知'') name ,COUNT(cid) as ''合计'','+@where+' id from tblCase crn left join tblFlow f on c.Flowid=f.Flowidrn left join tblFlowCategory fc on f.FlowCategoryid =fc.FlowCategoryidrn left join tblType t on fc.typeid=t.Typeid where rn (CommunityID='+@Communityid+' or '+@Communityid+' is null) rn and (CONVERT(varchar(100),c.HappenTime,23)>='+@Stime+' or '+@Stime+' is null)rnand (CONVERT(varchar(100),c.HappenTime,23)<='+@Etime+' or '+@Etime+' is null) rn group by '+@where+','+@name+'rn rn order by ''合计'' desc'rnexec(@strsql)rnrnendrnrnrn我感觉就是拼字符串那有问题啊。大家帮帮忙啊。
大家帮我看个SQL2008字符串转换时间问题。执行提示从字符串转换日期和/或时间时,转换失败
ALTER proc [dbo].[Sp_tj_Sjtj]rn(rn @Communityid varchar(10),rn @type varchar(5) ,rn @Stime datetime, --开始时间rn @Etime datetime --截止时间rn)rnasrn rnbeginrndeclare @strsql varchar(8000),rn @name varchar(20),rn @where varchar(50)rn if @Communityid='0' or @Communityid='' or @Communityid =null or @Communityid is null rn set @Communityid ='null'rn IF @Stime = ''rn SET @Stime = NULL rn IF @Etime = ''rn SET @Etime = NULLrn if(@type='1')rn beginrn set @name='TypeName'rn set @where='t.Typeid';rn endrn else if(@type='2')rn beginrn set @name='FlowCategoryName'rn set @where='fc.FlowCategoryid';rn endrn elsern beginrn set @name='FlowName'rn set @where='f.Flowid';rn endrn rn rn set @strsql ='rn rn select isnull( '+@name+',''未知'') name ,COUNT(cid) as ''合计'','+@where+' id from tblCase crn left join tblFlow f on c.Flowid=f.Flowidrn left join tblFlowCategory fc on f.FlowCategoryid =fc.FlowCategoryidrn left join tblType t on fc.typeid=t.Typeid where rn (CommunityID='+@Communityid+' or '+@Communityid+' is null) rn and (CONVERT(varchar(100),c.HappenTime,23)>='+@Stime+' or '+@Stime+' is null)rn and (CONVERT(varchar(100),c.HappenTime,23)<='+@Etime+' or '+@Etime+' is null) rn group by '+@where+','+@name+'rn rn order by ''合计'' desc'rnexec(@strsql)rnrnend
從 字元字串转换成日期及/或时间时,转换失败
儲存數據時出現:從 字元字串转换成日期及/或时间时,转换失败,我是業余愛好新手,求解決方法rnrnPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Clickrn If Form1.a1 = True Thenrnrn If ComboBox2.Text = "" Thenrn MsgBox("有欄位未填數據")rn Elsern Dim constr As Stringrnrn constr = ("Data Source=mark-pc\SQLEXPRESS;Initial Catalog=engineer;Integrated Security=False;User ID=sa;Password=123456;")rn sqlcon.ConnectionString = constrrn sqlcon.Open()rnrn sqlcmd.CommandText = "select * from mjbm"rn sqlcmd.Connection = sqlconrnrn Dim myadapter As New SqlDataAdapterrnrn myadapter.SelectCommand = sqlcmdrn myadapter.Fill(myds)rn Dim i As Integer = 0rn Dim j As Boolean = Falsern For i = 0 To myds.Tables(0).Rows.Count - 1 Step 1rn If TextBox1.Text = myds.Tables(0).Rows(i)(0) Thenrn j = Truern End Ifrn Nextrn If j = True Thenrn MsgBox("已有此項了哦!")rn sqlcon.Close()rn Elsern sqlcmd.CommandText = "insert into mjbm(類別,編碼,結構,名稱,開模廠商,日期,適用客戶,適用品名,編碼者) values('" & (ComboBox1.Text) & "','" & TextBox1.Text & "','" & ComboBox2.Text & "','" & TextBox2.Text & "','" & ComboBox3.Text & "','" & DateTimePicker1.Text & "','" & TextBox3.Text & "','" & TextBox4.Text & "','" & ComboBox4.Text & "')"rnrn sqlcmd.Connection = sqlconrn sqlcmd.ExecuteNonQuery()rn If MessageBox.Show("添加成功是否繼續添加", "成功", MessageBoxButtons.YesNo, MessageBoxIcon.Asterisk) = Windows.Forms.DialogResult.Yes Thenrnrn Me.Refresh()rnrn ComboBox1.Text = ""rn ComboBox2.Text = ""rn ComboBox3.Text = ""rn ComboBox4.Text = ""rn TextBox1.Text = ""rn TextBox2.Text = ""rn TextBox3.Text = ""rnrn TextBox4.Text = ""rnrn sqlcon.Close()rn Elsernrn sqlcon.Close()rn Me.Close()rn End Ifrn End Ifrn End If
SQL 批量转换 字符串转换日期
sql 实例 批量转换 字符串转换日期
SQL SERVER 日期格式化、日期和字符串转换
&#13; SQL SERVER 日期格式化、日期和字符串转换 &#13; &#13; &#13; &#13; &#13; sql server 中怎么把字符串转化为日期? ...
各位高手,帮帮忙:怎样从字符串转换日期和/或时间
rnrn[color=#FF0000] DateTime time = startTime.AddDays(j);rn string sql = "Select * from ProjectLogin where ProjectID='" + id + "' and RecordDate=cast(convert(varchar,'" + time + "',111)as datetime)";rnrnrnrn运行时,提示我:rnrn“/”应用程序中的服务器错误。rn--------------------------------------------------------------------------------rnrn从字符串转换日期和/或时间时,转换失败。 rn说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。 rnrn异常详细信息: System.Data.SqlClient.SqlException: 从字符串转换日期和/或时间时,转换失败。rnrn源错误: rnrnrn行 114: DataSet ds = new DataSet();rn行 115: ds.Reset();rn行 116: da.Fill(ds);rn行 117:rn行 118: if (ds.Tables[0].Rows.Count == 0)rn rn
[sql server] 从字符串向 datetime 转换时失败
[color=#3366FF]dbo_a 表[/color]rn id int identity(1,1),rn m_name varchar(20),rn [color=#00CCFF]m_start datetime,rn m_expire datetime[/color]rn[color=#3366FF]dbo_b [/color]rn m_name varchar(20),rn [color=#00CCFF] m_start datetime,rn m_expire datetime[/color]rnrn[color=#3366FF]现在,要把dbo_a表中 ,过过期 m_expire>=getdate() 的记录移至dbo_b [/color]rnrn使用游标: rndeclare @m_id int ,@m_name varchar(20), @m_start datetime ,@m_expire datetimerndeclare mycursor cursor scroll forrnselect * from dbo_a where m_expire>=getdate()rndeclare @i intrnopen mycursorrn set @i= @@cursor_rowsrn while @i>0rnbegin rn [color=#FF0000]fetch next from mycursor into @m_id,@m_name,@_start,@m_expire[/color] --****提示 [color=#FF0000]从字符串向 datetime 转换时失败[/color]rnrn set @i=@i-1rn insert into mail_history values (m_name,@_start,@m_expire)rn if( @@fetch_status!=0)rn beginrn delete from mail_queue where M_id=@m_id rn set @@fetch_status=0rn end rnendrnclose mycursorrndeallocate mycursorrnrn我想可能是,从游标行中读取的都是字符类型的rnrn所以我做了下面的更改rn////////////////rndeclare @m_id int ,@m_name varchar(20), @m_start [color=#FF00FF]varchar(50) [/color],@m_expire[color=#FF0000] varchar(50)[/color] --这里更改成varchar类型rndeclare mycursor cursor scroll forrnselect * from dbo_a where m_expire>=getdate()rndeclare @i intrnopen mycursorrn set @i= @@cursor_rowsrn while @i>0rnbegin rn fetch next from mycursor into @m_id,@m_name,@_start,@m_expire rn set @i=@i-1rn insert into mail_history values (m_name,[color=#FF0000]convert(datetime,@_start),convert(datetime,@m_expire))[/color] ---*****[color=#FF0000]这里提示从字符串向 datetime 转换时失败[/color] rn if( @@fetch_status!=0)rn beginrn delete from mail_queue where M_id=@m_id rn set @@fetch_status=0rn end rnendrnclose mycursorrndeallocate mycursorrnrn这是为什么啊??
qt写入文本文件失败
rnQFIle *localFile = new QFile(fileName);rnif(!localFile->open(QFile::WriteOnly))rnrn qDebug()<<"open file error";rn QMessageBox::information(this,"","open file error");rn return ;rnrn文件创建和打开都是成功的。rnrnif(bytesReceived < totalBytes)rnrn bytesReceived += tempConnection->bytesAvailable();//tempConnection是个QTcpSocketrn QByteArray inBlock = tempConnection->readAll();rn qint64 len=localFile->write(inBlock);rn QMessageBox::information(this,"",inBlock);rn rnrn我用QMessageBox显示inBlock中要写入文件的内容,是对的,而且write的返回值len也是对的,可打开文件却是空的?搞了一晚上了,就是查不出错误?恳请大家帮助!!!rn
SQL Server数据类型--日期和时间
在 SQL Server 中,每个列、局部变量、表达式和参数都具有一个相关的数据类型。下面介绍日期和时间类型: --日期 SELECT CONVERT(date,GETDATE()) --日期:2016-05-03 --用于定义一个与采用 24 小时制并带有秒小数部分的一日内时间相组合的日期 SELECT CONVERT(datetime,GETDATE())
sql server 日期,时间获取
select GETDATE();--获取当前日期 select CONVERT(varchar,GETDATE(),120) --获取当前日期(格式化) select DATENAME(YYYY,GETDATE()) --年 select DATENAME(YEAR,GETDATE()) --年 select DATEPART(YYYY,GETDATE()) --年 select DATEPA...
sql字符串转换日期
类似“2006年8月15日”这样在sqlsever数据库以字符串方式存放,请问如何把他在查询的时候转换成日期型。譬如查询所有2006年6月3日以前的该怎么写?
Qt 中QDate和QString的转化
QDate QDate::​fromString(const QString &amp;amp; string, const QString &amp;amp; format) 例如: QString str=&quot;2015/2/12&quot;; QDate date=QDate::fromString(str,&quot;yyyy/M/d&quot;); 一定要注意日期格式的用法! 表达式     输出 d          ...
][SQL Server]从字符串转换为 datetime 时发生语法错误。
HTTP 错误 500.100 - 内部服务器错误 - ASP 错误rnInternet 信息服务rnrn--------------------------------------------------------------------------------rnrn技术信息(用于支持人员)rnrn错误类型:rnMicrosoft OLE DB Provider for ODBC Drivers (0x80040E07)rn[Microsoft][ODBC SQL Server Driver][SQL Server]从字符串转换为 datetime 时发生语法错误。rn/Write.asp, 第 71 行rnrnrn浏览器类型:rnMozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; CIBA; InfoPath.2) rnrn网页:rnPOST 223 ??? /Write.asprnrnrnrnsql="INSERT INTO messageInfo (title, content, name, email, ip,qq,u_time) VALUES('" & vtitle & "','" & vcontent & "','" & vname & "','"& vemail & "','"& vip &"','"& vqq &"','"& now() &"')" rnrnConn.Execute(sql) [color=#FF0000]71行[/color]rnrnPOST Data:rnname=%BA%A3%B1%B4&email=ccfyy2008@163.com&qq=1013856522&title=%B2%E2%CA%D4&content=%B2%E2%CA%D4%B2%E2%CA%D4%B2%E2%CA%D4%B2%E2%CA%D4%B2%E2%CA%D4%B2%E2%CA%D4%B2%E2%CA%D4%B2%E2%CA%D4%B2%E2%CA%D4%B2%E2%CA . . . rnrn时间:rn2010年9月22日, 上午 10:58:47
从oracel到Sql Server的转换??
那位高人能告诉小弟一下,如何从oracel数据库导数据到sql server里,最好是具体一下,有步骤的流程,多谢,分布够我继续加
如何在SQL SERVER 2000中插入日期时没有时间,插入时间时没有日期?
数据类型为DATETIME,或者SMALLDATETIME,rn我在插入日期时总是带时间(如1995-12-02),在插入时间时总是带日期(如11:07:08),大侠们,跟我说说是怎么回事呀!rn在插入日期是1995-12-02,而在数据库中查看时,成了1995-12-02 00:00:00,rn在插入时间是11:07:08,而在数据库中查看时,成了1900-01-01 11:07:08。rn谢谢!
日期与时间的转换问题
C#.NET 中如何从rn2007/8/4 下午 06:00:00rn取得 18:00 的形式呀
日期和时间的转换问题
一个要求时间精确到毫秒(在豪秒级别不能有误差)的程序,GetLocalTime api似乎在豪秒级别精度不够?rnrn于是我想通过一些更高精度的方法获得当前时间距离从1970年1月1日0时0分0秒0豪秒的豪秒数,不知道有什么好的方法?rnrn另外获得这个豪秒数后,有什么高效的方法将其分离回 年 月 日 分 秒 豪秒 这6个数值?
JSONArray转换日期报错
cxf客户端调用服务端代码报错javax.xml.ws.soap.SOAPFaultException: java.lang.reflect.InvocationTargetExce。,   首先这个错误可能有千万种原因引起的,我们要做的是怎么精确定位到错误,首先先检查自己调用的方法,传入的参数,或者参数顺序跟调用方法的参数顺序是否一致, 如果不一致也可能引起错误,我之前测试的时候大意参数顺序
mysql 日期与时间的转换
里面详细介绍了mysql中日期与时间戳的转换
? 日期与时间的转换问题
C#.NET 中如何从rn2007/8/4 下午 06:00:00rn取得 18:00 的形式呀rn
相关热词 c#异步发送kafka c#窗体编号 c# 操作二进制文件 c# 反射 机制 c#线程 窗体失去响应 c#角度转弧度 c# 解析gps数据 c# vs设置 语法版本 c# json含回车 c#多线程demo