C#访问插入错误! [英] C# Access insert error !

查看:70
本文介绍了C#访问插入错误!的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

                      OleDbConnection con = new OleDbConnection();
           con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" + Application.StartupPath + "\\kodmatikdatabase.accdb";

con.Open();
           OleDbCommand sorgu = new OleDbCommand(("insert into geneltablo (KodAdi,Aciklama,GirisTarihi,Link,ProgramlamaDili,Puan,Durum) values (@KodAdi,@Aciklama,@GirisTarihi,@Link,@ProgramlamaDili,@Puan,@Durum)"),con);
           sorgu.Parameters.AddWithValue("@KodAdi", textBox1.Text);
           sorgu.Parameters.AddWithValue("@Aciklama", richTextBox1.Text);
           sorgu.Parameters.AddWithValue("@GirisTarihi", dateTimePicker1.Text);
           sorgu.Parameters.AddWithValue("@Link", textBox2.Text);
           sorgu.Parameters.AddWithValue("@ProgramlamaDili", comboBox1.Text);
           sorgu.Parameters.AddWithValue("@Puan", comboBox3.Text);
           sorgu.Parameters.AddWithValue("@Durum", comboBox2.Text);


           sorgu.ExecuteNonQuery();




当我按下按钮


"sorgu.ExecuteNonQuery();"在这一行

总是给我这个错误

条件表达式中的数据类型不匹配."


怎么了 ? :confused :: confused :: confused:




when i push button


" sorgu.ExecuteNonQuery(); " in this line

always give me this error

"Data type mismatch in criteria expression."


What is wrong ? :confused::confused::confused:

推荐答案

我怀疑问题出在这里:

sorgu.Parameters.AddWithValue("@GirisTarihi", dateTimePicker1.Text);

如果目标字段是Access数据库中的datetime值,则将导致错误.在添加参数之前,您需要将此值转换为日期时间.另外,如果数据库中的其他任何参数都是数字值,则需要将xx.Text值转换为适当的数字类型.
I suspect the problem is here:

sorgu.Parameters.AddWithValue("@GirisTarihi", dateTimePicker1.Text);

If the target field is a datetime value in the Access database, this will cause an error. You''ll need to cast this value to a datetime before you add the parameter. Additionally, if any of the other parameters are numeric values in the database, you''ll need to cast the xx.Text value into the appropriate numeric type.


这篇关于C#访问插入错误!的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆