问题描述
我收到此错误:
从字符串转换日期和/或时间时转换失败。在System.Data.SqlClient在System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject)的System.Data.SqlClient.SqlInternalConnection.OnError(SqlException异常,Boolean breakConnection,Action`1 wrapCloseInAction)中的.SqlConnection.OnError(SqlException异常,Boolean breakConnection,Action`1 wrapCloseInAction) stateObj,Boolean callerHasConnectionLock,Boolean asyncClose)
当我将它插入我的桌子时。
我使用的Sql数据类型
的时间:时间(07)
日期:date
我的代码是
I am getting this error:
" Conversion failed when converting date and/or time from character string. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) ""
When i am inserting it in to my table.
Sql data type i used
for time :time(07)
date: date
My code is
SqlCommand cmd;
con = new SqlConnection(ConfigurationManager.ConnectionStrings["hrms3"].ConnectionString);
String u = Session["user_id"].ToString();
Label1.Text = Session["user_id"].ToString();
cmd = new SqlCommand("insert into timesheet(user_id,timein,timeout,date) values(@user_id,@timein,@timeout,@date)", con);
//cmd = new SqlCommand("update login_admin set secure_pass='" + abc + "' where mail_id='" + admin_usermailid.Text + "'"); // cmd = new SqlCommand("update login_admin set secure_pass='" + admin_username.Text + "' where mail_id='" + admin_usermailid + "'");
//cmd = new SqlCommand("update news1 set news='" + admin_username.Text + "'where id='1'");
con.Open();
cmd.Parameters.AddWithValue("@user_id", u);
//cmd.Parameters.AddWithValue("@days", day.Text.ToString());
cmd.Parameters.AddWithValue("@timein", SqlDbType.Time).Value = time.Text;
cmd.Parameters.AddWithValue("@timeout", "0000");
//cmd.Parameters.AddWithValue("@worked", "");
cmd.Parameters.AddWithValue("@date",SqlDbType.Date).Value= DivTag.Text;
cmd.ExecuteNonQuery();
con.Close();
ClientScript.RegisterStartupScript(GetType(), "Onload", "alert('Thanks to submit login. Takecare')", true);<
推荐答案
这篇关于插入期间出错在从字符串转换日期和/或时间时转换失败。在System.Data.SqlClient.SqlConnection.OnError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!