关于字符串转换为Datatime的问题,求助! 现在要在雇员表中插入数据,但是在出生日期,和雇佣日期中,无论输入一组数字,还是0000-00-00形式的日期,都提示如下的错误出生日期 和雇佣日期在SQL数据库中的类型都是smalldatatime而在订单里面插如数据时,没有这样的错误,我在订购日期里输入123,点插入后,自动转为1900-5-4.到底是怎么回事呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 不好意思,上传资料我还以为是照片,原来是供下载的.错误信息为 "输入字符串的格式不正确"插入按纽的代码如下private void button14_Click(object sender, EventArgs e) { string inserStr = string.Format("INSERT INTO 雇员 VALUES({0},'{1}','{2}','{3}','{4}',{5}, {6},'{7}','{8}','{9}','{10}','{11}','{12}','{13]','{14}',{15})", textBox56.Text, textBox57.Text, textBox58.Text, textBox59.Text, textBox60.Text, textBox61.Text, textBox62.Text, textBox63.Text, textBox64.Text, textBox65.Text, textBox66.Text, textBox67.Text, textBox68.Text, textBox69.Text, textBox70.Text, textBox71.Text); SqlCommand InsertCommand = new SqlCommand(inserStr, myConn); myConn.Open(); try { InsertCommand.ExecuteNonQuery(); } catch (SqlException ex) { MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error); } myConn.Close(); DisplayDB7(); } 数据类型用datetime试试.插入的时候把文本转换成DateTime数据类型看看. 数据库的时间数据类型不要用samlldatetime类型,用datetime看看. 找到错误了,原来是string inserStr = string.Format("INSERT INTO 雇员 VALUES({0},'{1}','{2}','{3}','{4}',{5}, {6},'{7}','{8}','{9}','{10}','{11}','{12}','{13]','{14}',{15})",里面某个大括号,写成了中括号,呵呵 谢谢楼上两位! C# 串口通信、单片机的似乎很少,我汇总了一些,大家也一起来汇总吧 请问大家C#里面有没有类似于C++中模板的功能?C#有没有类似STD模板库的类容? wpf中,tabcontrol 我想写一个c#连接数据库的公共类 怎么写 如何在.net安装程序打包过程中自动注册ocx控件,请大侠赐教 重构一个表 请教过来人 双色球中奖判断程序 C# 成员 初 始 化 顺 序--------大考了!! 不许用VS 打包之后,如何直接双击运行 sql如何取得首字母? C# MessageBox.Show() 位置父窗体居中?
插入按纽的代码如下
private void button14_Click(object sender, EventArgs e)
{
string inserStr = string.Format("INSERT INTO 雇员 VALUES({0},'{1}','{2}','{3}','{4}',{5}, {6},'{7}','{8}','{9}','{10}','{11}','{12}','{13]','{14}',{15})", textBox56.Text, textBox57.Text, textBox58.Text, textBox59.Text, textBox60.Text, textBox61.Text, textBox62.Text, textBox63.Text, textBox64.Text, textBox65.Text, textBox66.Text, textBox67.Text, textBox68.Text, textBox69.Text, textBox70.Text, textBox71.Text);
SqlCommand InsertCommand = new SqlCommand(inserStr, myConn);
myConn.Open();
try
{
InsertCommand.ExecuteNonQuery();
}
catch (SqlException ex)
{
MessageBox.Show(ex.Message, "Error!", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
myConn.Close();
DisplayDB7();
}
插入的时候把文本转换成DateTime数据类型看看.
里面某个大括号,写成了中括号,呵呵
谢谢楼上两位!