求助,总是出现从字符串转换日期和/或时间时,转换失败这个错误

private void gridviewbind()
{
SqlConnection myConn = new SqlConnection(connStr);
string S5 = Request.QueryString["a"];
DateTime S1 = Convert.ToDateTime(S5);
string S2 = Request.QueryString["b"];
string S3 = Request.QueryString["c"];
string S4 = Request.QueryString["d"];
SqlDataAdapter myDa = new SqlDataAdapter("select * from V4 where 时间='" + S1 + "&收银员" + S2 + "&商品种类" + S3 + "&品名" + S4 +"'", myConn);
myConn.Open();
DataSet myDataSet = new DataSet();
myDa.Fill(myDataSet);
GridView1.DataSource = myDataSet.Tables[0];
GridView1.DataBind();
myConn.Close();
}
错误:从字符串转换日期和/或时间时,转换失败
这个怎么解决

2个回答

public static String dataToString(java.util.Date dt, String type) {
String returnStr = null;
if (dt == null) {
return null;
} else {
// YYYY-MM-DD HH24:MI:SS
type = StringUtil.StringReplace("YYYY", "yyyy", type);
type = StringUtil.StringReplace("DD", "dd", type);
type = StringUtil.StringReplace("SS", "ss", type);
type = StringUtil.StringReplace("hh24", "HH", type);
type = StringUtil.StringReplace("HH24", "HH", type);
type = StringUtil.StringReplace("MI", "mm", type);
type = StringUtil.StringReplace("mi", "mm", type);
}
if (type == null || type.trim().equals("")) {
returnStr = DateFormat.getDateTimeInstance().format(dt);
} else {
SimpleDateFormat f = new SimpleDateFormat(type);
returnStr = f.format(dt);
}
return returnStr;
}

 * 转换的格式类型可以自行定义(其中年yyyy月MM日dd时HH分mm秒ss):<br>
 * (1)转换成yyyy-MM-dd HH:mm:ss格式:2005-5-25 10:50:24<br>
 * (2)转换成yyyy年MM月dd日 HH:mm:ss格式:2005年5月25日 10:50:24<br>
 * (3)转换成yyyyMMddHHmmss格式:20061024152356<br>
 * (4)转换成yyyy-MM-dd格式:2006-12-11<br>
 * (5)转换成yyyyMMdd格式:20061211<br>
 * (5)转换成yyyyMM格式:200612<br>
 * (6)转换类型null时,格式默认为yyyy-MM-dd HH:mm:ss
qq_34730277
南宫文凯 回复baidu_39252619: 殊途同归
大约 2 年之前 回复
baidu_39252619
baidu_39252619 能不能就题看一下,这是VS上的
大约 2 年之前 回复

楼主想要的日期格式是什么的 ?
我们可以通过使用DataTime这个类来获取当前的时间。通过调用类中的各种方法我们可以获取不同的时间:如:日期(2008-09-04)、时间(12:12:12)、日期+时间(2008-09-04 12:11:10)等。

//获取日期+时间
DateTime.Now.ToString(); // 2008-9-4 20:02:10
DateTime.Now.ToLocalTime().ToString(); // 2008-9-4 20:12:12

//获取日期
DateTime.Now.ToLongDateString().ToString(); // 2008年9月4日
DateTime.Now.ToShortDateString().ToString(); // 2008-9-4
DateTime.Now.ToString("yyyy-MM-dd"); // 2008-09-04
DateTime.Now.Date.ToString(); // 2008-9-4 0:00:00

//获取时间
DateTime.Now.ToLongTimeString().ToString(); // 20:16:16
DateTime.Now.ToShortTimeString().ToString(); // 20:16
DateTime.Now.ToString("hh:mm:ss"); // 08:05:57
DateTime.Now.TimeOfDay.ToString(); // 20:33:50.7187500

//其他
DateTime.ToFileTime().ToString(); // 128650040212500000
DateTime.Now.ToFileTimeUtc().ToString(); // 128650040772968750
DateTime.Now.ToOADate().ToString(); // 39695.8461709606
DateTime.Now.ToUniversalTime().ToString(); // 2008-9-4 12:19:14

DateTime.Now.Year.ToString(); 获取年份 // 2008
DateTime.Now.Month.ToString(); 获取月份 // 9
DateTime.Now.DayOfWeek.ToString(); 获取星期 // Thursday
DateTime.Now.DayOfYear.ToString(); 获取第几天 // 248
DateTime.Now.Hour.ToString(); 获取小时 // 20
DateTime.Now.Minute.ToString(); 获取分钟 // 31
DateTime.Now.Second.ToString(); 获取秒数 // 45

//n为一个数,可以数整数,也可以事小数
dt.AddYears(n).ToString(); //时间加n年
dt.AddDays(n).ToString(); //加n天
dt.AddHours(n).ToString(); //加n小时
dt.AddMonths(n).ToString(); //加n个月
dt.AddSeconds(n).ToString(); //加n秒
dt.AddMinutes(n).ToString(); //加n分

SQL语句使用时间和日期的函数

getdate():获取系统当前时间
dateadd(datepart,number,date):计算在一个时间的基础上增加一个时间后的新时间值,比如:dateadd(yy,30,getdate())
datediff(datepart,startdate,enddate):计算两个时间的差值,比如:datediff(yy,getdate(),'2008-08-08')
dataname(datepart,date):获取时间不同部分的值,返回值为字符串
datepart(datepart,date):和datename相似,只是返回值为整型
day(date):获取指定时间的天数
month(date):获取指定时间的月份
year(date):获取指定时间的年份

select year(getdate()) :当前年份

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
其他相关推荐
错误-从字符串转换日期和/或时间时,转换失败
在敲上机的时候,将用户上机信息插入到Online表中一直出现这个错误,以下时图片和解决办法 1.查看实体的数据类型是否正确(DateTime) 2.查看数据库中的数据类型是否正确(DateTIme) 3.查看Main中是否将string类型的数据转换为Datetime类型 4.数据库插入语句错误 以下是一一对应的正确的代码 1. 2. 3. 4. ...
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
从字符串转换日期和/或时间时,转换失败。
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
从字符串转换日期和/或时间时,转换失败
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 从字符串转换日期和/或时间时,转换失败
修改系统时间显示格式就行了
从字符串转换日期和/或时间时,转换失败。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)))
老是提示从字符串转换日期和/或时间时,转换失败。
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列 是日期格式, 但是我已经加了‘’‘ ,请高人帮忙看一下 该如何修正,非常感谢。
从字符串转换日期和/或时间时 转换失败。
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"); 这个不是我想要的。
从字符串转换日期和/或时间时,转换失败。 急
[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从字符串转换日期和/或时间时,转换失败。
字符串转换为日期或时间时,转换失败
用程序调用存储过程时出现标题错误rn但直接exec存储过程时却正常,传的参数是一样的,都是字符串rn为什么呢?
asp.net/C#:从字符串转换日期和/或时间时,转换失败。
网页代码在其他人电脑上就可以正常运行,在我的电脑上就报错:从字符串转换日期和/或时间时,转换失败。rn向数据库中插入一条数据,数据库字段为date型,数据来源于日历控件的值,代码为 DateTime day = Calendar1.SelectedDate;rn请教大神是什么原因,同样的代码在其他人的电脑上可以正常运行
从字符串转换日期和/或时间时,转换失败怎么解决
从字符串转换日期和/或时间时,转换失败。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
求助,从字符串转换日期和/或时间时,转换失败,但结果显示正常
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提示从字符串转换日期和/或时间时,转换失败,但是结果却是正常的,请问怎么解决
求助:从字符串转换日期和/或时间时,转换失败。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]
從 字元字串转换成日期及/或时间时,转换失败
儲存數據時出現:從 字元字串转换成日期及/或时间时,转换失败,我是業余愛好新手,求解決方法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中插入语句参数格式&&从字符串转换日期和/或时间时,转换失败
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
一模一样的的存储过程,执行出来一个正确一个提示"从字符串转换日期和/或时间时,转换失败"
存储过程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存储过程几乎是一样的,只是表换了,传的参数也是一模一样。但是一个执行结果正确,另一个却提示“从字符串转换日期和/或时间时,转换失败”。 小弟实在不解,恳请各位大侠解答,万分感谢
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];
从字符串转换日期和/或时间时,转换失败。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我就是想计算时间差多少分钟,表的数据类型不变,求问大神怎么解决?
Qt Qdate写入sql server报错:从字符串转换日期和/或时间时,转换失败。
本人小白一个,做学校布置的大作业时遇到这样一个问题:nnnn```n query.prepare("INSERT INTO Orders(Name,Quantity,Weight,G_Type,Destination,Applicant,S_Date)"n "VALUES(:name,:quantity,:weight,:type,:destination,:applicant,:date)");n query.bindValue(":name",ui->NameEdit->text());n query.bindValue(":quantity",ui->quanEdit->value());n query.bindValue(":weight",ui->WeigEdit->value());n query.bindValue(":type",ui->TypeEdit->text());n query.bindValue(":destination",ui->DestinEdit->text());n query.bindValue(":applicant",Applicant);n query.bindValue(":date",QDate::currentDate().toString("yyyy-mm-dd"));nn query.exec();n```n结果报错:QODBCResult::exec: Unable to execute statement: "[Microsoft][ODBC SQL Server Driver][SQL Server]从字符串转换日期和/或时间时,转换失败。"n实在不知道该怎么办,求大神解答。n
SQL union 从字符串转换日期和/或时间时,转换失败(基础知识不牢固导致坑爹的问题)
今天生成环境出现了一个问题,在使用UNION联合查询两个订单表的时候,老是提示: 从字符串转换日期和/或时间时,转换失败,然后看了一下数据,没有问题啊,所有的时间都是有数据并且格式十分正确。
对数据库中的时间字段插入值时,老是说从字符串转换日期和/或时间时,转换失败
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
SQL 批量转换 字符串转换日期
sql 实例 批量转换 字符串转换日期
asp.net关闭后,总是出这个错误
asp.net关闭后,总是出这个错误,为什么?rnrnhttp://eu.webmatrixhosting.net/oowowo/rnrn这有发生错误的图片.
日期与时间的转换问题
C#.NET 中如何从rn2007/8/4 下午 06:00:00rn取得 18:00 的形式呀
日期和时间的转换问题
一个要求时间精确到毫秒(在豪秒级别不能有误差)的程序,GetLocalTime api似乎在豪秒级别精度不够?rnrn于是我想通过一些更高精度的方法获得当前时间距离从1970年1月1日0时0分0秒0豪秒的豪秒数,不知道有什么好的方法?rnrn另外获得这个豪秒数后,有什么高效的方法将其分离回 年 月 日 分 秒 豪秒 这6个数值?
? 日期与时间的转换问题
C#.NET 中如何从rn2007/8/4 下午 06:00:00rn取得 18:00 的形式呀rn
mysql 日期与时间的转换
里面详细介绍了mysql中日期与时间戳的转换
时间 日期 转换
时间戳去掉毫秒数: public void test56() throws ParseException { Timestamp timestamp = new Timestamp(System.currentTimeMillis()); System.out.println("old time stamp: "+timestamp); S...
[求助]字符串转换转换问题(简单)
大家好!我刚刚接触delphi,有一个小问题请高手指点一下。rnrn&0004 = 00farn&0005 = 000arnrn有一个文本里面的内容都是上面类似的内容,我要把“&”和“=”中间的数(例如0004)赋给一个word类型的数,我用Readln()函数读出文本一行赋给一个字符串temp,然后再用一个字符串S保存temp的第2到第5位,我现在想把S转换成word类型的十六进制数,这一步我不知道怎么实现?请各位高手不吝赐教,谢谢!
各位高手,帮帮忙:怎样从字符串转换日期和/或时间
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
将字符串转换为日期和时间,或日期转换为字符串格式
package com.yanshu; import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Date; public class Test { public static void mai
字符串转换日期
字符串20100830如何转换成日期型啊,希望各位高手帮一下忙
一组日期查询出最近时间的日期?
code datetimern1 2014-1-1rn1 2014-1-5rn1 2014-1-10rn2 2014-1-1rn2 2014-1-19rn4 2014-1-1rn6 2014-1-1rn6 2014-2-3rnrnrn只想得到日期,如何简便的得到离现在日期最近的一组日期?且CODE为1
日期与字符串转换
String dateString = “Tue Apr 15 11:23:55 CST 2014”; SimpleDateFormat sfEnd = new SimpleDateFormat(“yyyy-MM-dd HH:mm:ss”); SimpleDateFormat sfStart = new SimpleDateFormat(“EEE MMM dd HH:mm:ss zzz ...
从DTPicker到出日期,时间?
DTPicker1.Value='2003-5-8'rnDTPicker2.Value='16:44:21'rnrn Dim dbNow As Doublern dbNow = Format(Now(), "yyyymmddhhnnss")rn ’dbNow 可能等于 20030508164421rnrn此时我想从DTPicker1,DTPicker2得到一个 Double 类型的数据来和 dbNow 比较rnrn我改怎么办?
求助:为什么我老出这个错误?
fatal error RC1015: cannot open include file 'res\mcsdev.rc2'.rnrn我从网上下载了一个例子源代码。出现这个问题,请问怎么处理?rn
吐血求助:为什么总是出现这个错误?
在留言板界面上写好名字和内容后,存入数据库的时候总是出现如下错误:rnorg.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.rnrnC:\Program Files\Apache Tomcat 4.0\work\Standalone\localhost\examples\post$jsp.java:137: Incompatible type for method. Explicit cast needed to convert java.lang.Throwable to java.lang.Exception.rn if (pageContext != null) pageContext.handlePageException(t);rn ^rnNote: C:\Program Files\Apache Tomcat 4.0\work\Standalone\localhost\examples\post$jsp.java uses or overrides a deprecated API. Recompile with "-deprecation" for details.rn1 error, 2 warningsrn写入数据库的源文件如下:rn<%@page import="java.sql.*"%>rnrnrn 发表文章rnrnrn<%!rnpublic String GBK2UNI(String s)throws Exceptionrn String temp=new String(s.getBytes("GBK"),"ISO8859-1");rn return temp;rnrn%>rn<%rnString name=GBK2UNI(request.getParameter("name").trim());rnString email=GBK2UNI(request.getParameter("email").trim());rnString content=GBK2UNI(request.getParameter("content").trim());rnString ip=GBK2UNI(request.getRemoteAddr());rnString exactpost=new java.util.Date().toLocaleString();rn%>rn<%rnint k=0;rnint i=content.indexOf('<',k);rnint j=content.indexOf('<',k);rnString s1=null;rnString s2=null;rnString s3=null;rnwhile(i!=-1&&j!=-1&&j>i)rnrns1=content.substring(i+1,j);rns1=s1.toUpperCase();rnif(s1.startsWith("SCRIPT")||s1.startsWith("/SCRIPT")||s1.startsWith("FORM")||s1.startsWith("INPUT")rn ||s1.startsWith("TEXTAREA")||s1.startsWith("/FORM"))rnrns1="FORBID"+s1;rns2=new String(content.substring(0,i+1));rns3=new String(content.substring(j,content.length()));rncontent=s2+s1+s3;rnrnk=j;rni=content.indexOf('<',k);rnj=content.indexOf('<',i);rnrnClass.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver").newInstance(); rnString url="jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=km";rnString password="";rnString user="sa";rnConnection conn=DriverManager.getConnection(url,user,password); rnStatement stmt=conn.createStatement();rnResultSet rs=stmt.executeQuery("select max(uid)from messagebook");rnwhile(rs.next())rnrnint NewID=rs.getInt(1);rnNewID++;rnrnrs.close();rnPreparedStatement pstmt=conn.prepareStatement("insert into messagebook(name,ip,email,exactpost,content)values(?????)");rnpstmt.setString(1,name);rnpstmt.setString(2,ip);rnpstmt.setString(3,email);rnpstmt.setString(4,exactpost);rnpstmt.setString(5,content);rnpstmt.executeUpdate();rnpstmt.close();rnstmt.close();rnconn.close();rn%>rn写入数据库成功!恭喜!Congratulations!rn返回留言簿rnrnrnrnrnrnrn到底是什么问题?如何解决?服务器是好的,以前也这样我把tomcat重装过了。rn请大家给我提出实质性的解决方法,我急啊!万分感谢!
相关热词 c#入门推荐书 c# 解码海康数据流 c# xml的遍历循环 c# 取 查看源码没有的 c#解决高并发 委托 c#日期转化为字符串 c# 显示问号 c# 字典对象池 c#5.0 安装程序 c# 分页算法