win7系统下aspx页面中向SQL数据库插入Datetime类型提示:从字符串转换日期和/或时间时,转换失败。我设了断点要插入的数据的值是2013-07-25 16:31:05,为什么插不进去?
是不是其他列的问题,设了datetime类型,插了string类型
这种格式字段自动对应的
@金正声: 是我SQL写错了没写插入到哪列,对应关系就错了 数据插错列了!
通过什么来插入的
代码贴出来看看
转换失败-->怎么转的啊?
一码胜千言:
var parameter = new SqlParameter("@CreateTime", System.Data.SqlDbType.DateTime); parameter.Value = feedBack.Createtime;
建议仔细检查代码~~~注意字段与数据的对应关系~
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加载确实显示:从字符串转换注册日期和/或时间时,转换失败。
feedBack.Createtime 是dateTime类型吗
那我为什么也是这个出错误??
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();
}