窗口应用程序中的数据网格视图中未更新日期 [英] Date is not updated in Data Grid View in Window Application
本文介绍了窗口应用程序中的数据网格视图中未更新日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用MS Access在我的ASP.NET Window应用程序中保存数据。当我在数据网格视图中更新日期时,它显示错误UPDATE语句中的语法错误,但是当我更新其他字段,如姓名,联系号码时,这些字段很容易更新。
I used MS Access to save data in my ASP.NET Window application. When I update date in Data Grid View it shows error "Syntax error in UPDATE statement" but when I update other field like Name, Contact No. then these fields is easily updated.
public partial class Form1 : Form
{
OleDbConnection con1;
OleDbDataAdapter da1;
DataTable dt1;
OleDbCommandBuilder cmb1;
private void Form1_Load(object sender, EventArgs e)
{
con1 = new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Day Book Data\db\DayBook.accdb;Persist Security Info=False;");
string query1 = "select * from paypayment";
da1 = new OleDbDataAdapter(query1, con1);
dt1 = new DataTable();
con1.Open();
da1.Fill(dt1);
dataGridView2.DataSource = dt1;
con1.Close();
}
private void button3_Click(object sender, EventArgs e)
{
cmb1 = new OleDbCommandBuilder(da1);
da1.Update(dt1);
}
推荐答案
我在这里感觉dataTable中Date字段的数据类型是DateTime,当你更新dataAdaptor时它将它作为网格Cell的字符串值。我建议你做一个正确的类型转换而不是更新操作。
What I feel here is the datatype of your Date field in dataTable is DateTime and when you are updating dataAdaptor it is taking it as a string value from grid Cell. I would suggest you to do a proper typecast and than do the update operation.
这篇关于窗口应用程序中的数据网格视图中未更新日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文