注册 登录
编程论坛 ASP.NET技术论坛

字符串转换成datetime类型时发生语法错误

doujiang 发布于 2008-04-12 20:58, 1043 次点击
我在表里的字段类型是datetime的
Convert.ToDateTime(txtbirth.Text)怎么会发生错误呢?
4 回复
#2
hebingbing2008-04-12 21:19
出现的错误是什么啊……
应该对吧?
#3
doujiang2008-04-12 21:43
错误提示
#4
hebingbing2008-04-12 22:05
应该没有错误吧……
我记得是可以的啊……
要不你换成DateTime.Parse(TextBox1.Text)试试,要是还不行你把你的代码贴出来看看……
#5
doujiang2008-04-12 22:24
还是解决不了,字段比较多
string ConnString = System.Configuration.ConfigurationSettings.AppSettings["ConnectionSql"];
            //从<AppSettings>节读取连接字符串     
SqlConnection sqlcon = new SqlConnection(ConnString);
//创建SqlConnection对象
sqlcon.Open();
string sqlinsert="insert into jmxx values('txthkno.Text.ToString()','txtid.Text.ToString()',"
+"'txtbno.Text.ToString()','txthno.Text.ToString()',"
+"'Drophktype.SelectedItem.Value ',"
+"'txtname.Text.ToString()',"
+"'txttel.Text.ToString()',"
+"'txtaddress.Text.ToString()',"
+"'Convert.ToInt32(txtcount.Text)',"
+"'Convert.ToInt32(txtmancount.Text)',"
+"'Convert.ToInt32(txtwomancount.Text)',"
+"'Convert.ToInt32(txtincome.Text)',"
+"'Dropeconomy.SelectedItem.Value',"
+"'Drophousetype.SelectedItem.Value',"
+"'txtfamilynote.Text.ToString()',"
+"'txtname.Text.ToString()',"
+"'txtprename.Text.ToString()',"
+"'Droprelation.SelectedItem.Value',"
+"'txtcardid.Text.ToString()',"
+"'txtsign.Text.ToString()',"
//+"'Convert.ToDateTime(txtsigndate.Text)',"
+"' DateTime.Parse(txtsigndate.Text)',"日期类型的
+"' DateTime.Parse(txtbirth.Text)',"日期类型的
//+"'Convert.ToDateTime((TextBox)(txtbirth.Text))',"
+"'txtbirthplace.Text.ToString()',"
+"'Dropsex.SelectedItem.Value',"
+"'Convert.ToInt32(txthigh.Text)',"
+"'Dropbloodtype.SelectedItem.Value',"
+"'Dropnation.SelectedItem.Value',"
+"'txthkplace.Text.ToString()',"
+"'txtjg.Text.ToString()',"
+"'Dropschool.SelectedItem.Value',"
+"'Dropmarry.SelectedItem.Value',"
+"'Droppolitical.SelectedItem.Value',"
+"'txtwork.Text.ToString()',"
+"'Dropmilitary.SelectedItem.Value',"
+"'TextBoxtel.Text.ToString()',"
+"'TextBoxnote.Text.ToString()',"
//+"'Convert.ToDateTime(txtintime.Text)',"
 +"' DateTime.Parse(txtintime.Text)',"日期类型的
 +"'txtpre.Text.ToString()',"
+"'txtinreason.Text.ToString()',"
 +"' DateTime.Parse(txtouttime.Text)',"日期类型的
//+"'Convert.ToDateTime(txtouttime.Text)',"
      +"'txtout.Text.ToString()','txtoutreason.Text.ToString()')";
SqlCommand comm = new SqlCommand(sqlinsert,sqlcon);
    comm.ExecuteNonQuery();
    sqlcon.Close();
    Response.Redirect("admin.aspx");
1