首页 新闻 会员 周边

从字符串转换日期和/或时间时,转换失败。

0
悬赏园豆:100 [已解决问题] 解决于 2013-07-25 19:41

win7系统下aspx页面中向SQL数据库插入Datetime类型提示:从字符串转换日期和/或时间时,转换失败。我设了断点要插入的数据的值是2013-07-25 16:31:05,为什么插不进去?

金正声的主页 金正声 | 初学一级 | 园豆:41
提问于:2013-07-25 16:46
< >
分享
最佳答案
0

是不是其他列的问题,设了datetime类型,插了string类型

收获园豆:100
jerry128 | 初学一级 |园豆:31 | 2013-07-25 18:34

这种格式字段自动对应的

金正声 | 园豆:41 (初学一级) | 2013-07-25 19:27

@金正声: 是我SQL写错了没写插入到哪列,对应关系就错了 数据插错列了!

金正声 | 园豆:41 (初学一级) | 2013-07-25 19:40
其他回答(7)
0

通过什么来插入的

Yu | 园豆:12980 (专家六级) | 2013-07-25 16:59

支持(0) 反对(0) 金正声 | 园豆:41 (初学一级) | 2013-07-25 17:38

支持(0) 反对(0) 金正声 | 园豆:41 (初学一级) | 2013-07-25 17:41
0

代码贴出来看看

小兵仔 | 园豆:1240 (小虾三级) | 2013-07-25 17:20

支持(0) 反对(0) 金正声 | 园豆:41 (初学一级) | 2013-07-25 17:39
0

转换失败-->怎么转的啊?

灰身 | 园豆:188 (初学一级) | 2013-07-25 17:37

支持(0) 反对(0) 金正声 | 园豆:41 (初学一级) | 2013-07-25 17:40
0

一码胜千言:

var parameter = new SqlParameter("@CreateTime", System.Data.SqlDbType.DateTime);
parameter.Value = feedBack.Createtime;

 

dudu | 园豆:30994 (高人七级) | 2013-07-25 18:18
0

建议仔细检查代码~~~注意字段与数据的对应关系~

幻天芒 | 园豆:37175 (高人七级) | 2013-07-25 18:43

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int userID = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
string UserName = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
string UserGender = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
string CreatedTime = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
string ispass = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text;
SqlConnection conn=
new SqlConnection(ConfigurationManager.ConnectionStrings["Constr"].ConnectionString);
string sqlString = "update UserInfo set UserName='" + UserName;
sqlString += "',UserGender='" + UserGender + "',CreatedTime='" + CreatedTime;
sqlString += "',IsPass='" + ispass + "'where UserID=" + userID;
conn.Open();
SqlCommand cmd = new SqlCommand(sqlString, conn);
cmd.ExecuteNonQuery();
GridView1.EditIndex = -1;
ShowAllUser();
conn.Close();
}
那我这个总不会有错吧,可是通过VS加载确实显示:从字符串转换注册日期和/或时间时,转换失败。

支持(0) 反对(0) 不瘦25斤不换头像 | 园豆:202 (菜鸟二级) | 2020-04-20 21:04
0
feedBack.Createtime 是dateTime类型吗
usday | 园豆:219 (菜鸟二级) | 2013-07-25 18:52

支持(0) 反对(0) 金正声 | 园豆:41 (初学一级) | 2013-07-25 19:25
0

那我为什么也是这个出错误??
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
int userID = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
string UserName = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
string UserGender = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
string CreatedTime = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
string ispass = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text;
SqlConnection conn=
new SqlConnection(ConfigurationManager.ConnectionStrings["Constr"].ConnectionString);
string sqlString = "update UserInfo set UserName='" + UserName;
sqlString += "',UserGender='" + UserGender + "',CreatedTime='" + CreatedTime;
sqlString += "',IsPass='" + ispass + "'where UserID=" + userID;
conn.Open();
SqlCommand cmd = new SqlCommand(sqlString, conn);
cmd.ExecuteNonQuery();
GridView1.EditIndex = -1;
ShowAllUser();
conn.Close();
}

不瘦25斤不换头像 | 园豆:202 (菜鸟二级) | 2020-04-20 20:54
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册