2 a360566014 a360566014 于 2016.05.08 17:33 提问

该字符未被识别为有效的datatime

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;
namespace 更新数据表
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

    private void Form1_Load(object sender, EventArgs e)
    {
        string sql_str;
        string constr = "server=.;database=CJGL;integrated security=true";
        SqlConnection myconnection = new SqlConnection(constr);
        try
        {
            myconnection.Open();
            sql_str = "select 学号,姓名,性别,出生日期,专业,学分 from student";
            SqlDataAdapter mydataadapter = new SqlDataAdapter(sql_str,myconnection);
            DataSet mydataset = new DataSet();
            mydataadapter.Fill(mydataset,"student");
            DataRow dr = mydataset.Tables[0].NewRow();
            dr["学号"] = textBox1.Text;
            dr["姓名"] = textBox2.Text;
            dr["性别"] = textBox3.Text;
            dr["出生日期"] = textBox4.Text;
            dr["专业"] = textBox5.Text;
            dr["学分"] = textBox6.Text;
            SqlCommandBuilder scb = new SqlCommandBuilder(mydataadapter);
            mydataset.Tables[0].Rows.Add(dr);
            mydataadapter.Update(mydataset,"student");
        }
            catch(Exception ex)
        {
                MessageBox.Show(ex.Message.ToString());
            }
        finally
         {
            myconnection.Close();
         }

        }
    }
}
    ![图片说明](http://img.ask.csdn.net/upload/201605/08/1462699983_513763.png)

2个回答

CSDNXIAOD
CSDNXIAOD   2016.05.08 17:42

该字符串未被识别为有效的 DateTime。
该字符串未被识别为有效的DateTime
System.FormatException: 该字符串未被识别为有效的 DateTime
----------------------biu~biu~biu~~~在下问答机器人小D,这是我依靠自己的聪明才智给出的答案,如果不正确,你来咬我啊!

Fat_qiang
Fat_qiang   2016.05.08 19:21

你应该把那几个textBox输入的内容贴出来啊,这样看代码是看不出问题的

Csdn user default icon
上传中...
上传图片
插入图片
准确详细的回答,更有利于被提问者采纳,从而获得C币。复制、灌水、广告等回答会被删除,是时候展现真正的技术了!