本人对数据库是菜鸟
最近要用到
C# 操作ACCESS 本地数据库问题 insert 成功 update 失败
try
                                    {
                                        this.custom_simpleTableAdapter.Insert(data_custom_simple_new.客户号,data_custom_simple_new.客户名称,
                                            data_custom_simple_new.当前权益,data_custom_simple_new.最高权益,data_custom_simple_new.最低权益,
                                            data_custom_simple_new.交易开始日期,data_custom_simple_new.数据更新日期,data_custom_simple_new.最近交易日期);
                                        this.custom_simpleTableAdapter.Fill(this.futuresTradeDataSet.custom_simple);
                                    }
                                    catch (System.Exception ex)
                                    {
                                        this.richTextBox2.Text =   ex.Message + "\n" + this.richTextBox2.Text;
                                    }
insert 代码如上,成功没有问题 form中有一个dataGridView 绑定数据库 custom_simple 为数据库中的一个表update 老是不成功 update 返回0 没有exception抛出 update代码DataRow newrow = this.futuresTradeDataSet.custom_simple.NewRow();//.Tables[0].NewRow();
                                        newrow["编号"] = data_custom_simple_new.编号;
                                        newrow["客户号"] = data_custom_simple_new.客户号;
                                        newrow["客户名称"] = data_custom_simple_new.客户名称;
                                        newrow["当前权益"] = data_custom_simple_new.当前权益;
                                        newrow["最高权益"] = data_custom_simple_new.最高权益;
                                        newrow["最低权益"] = data_custom_simple_new.最低权益;
                                        newrow["交易开始日期"] = data_custom_simple_new.交易开始日期.Date.ToLongDateString();
                                        newrow["数据更新日期"] = data_custom_simple_new.数据更新日期.Date.ToLongDateString();
                                        newrow["最近交易日期"] = data_custom_simple_new.最近交易日期.Date.ToLongDateString();
                                        int retint = this.custom_simpleTableAdapter.Update(newrow);
this.custom_simpleTableAdapter.Fill(this.futuresTradeDataSet.custom_simple);
另外用update的另一个方法也不能成功update 代码如下int retint= this.custom_simpleTableAdapter.Update(data_custom_simple_new.客户号,
                                            data_custom_simple_new.客户名称,
                                            data_custom_simple_new.当前权益,
                                            data_custom_simple_new.最高权益,
                                            data_custom_simple_new.最低权益,
                                            data_custom_simple_new.交易开始日期,
                                            data_custom_simple_new.数据更新日期,
                                            data_custom_simple_new.最近交易日期,
                                            int.Parse(data_custom_simple_old.编号.ToString()),                                            data_custom_simple_old.客户号,
                                            data_custom_simple_old.客户名称,
                                            data_custom_simple_old.当前权益,
                                            data_custom_simple_old.最高权益,
                                            data_custom_simple_old.最低权益,
                                            data_custom_simple_old.交易开始日期,
                                            data_custom_simple_old.数据更新日期,
                                            data_custom_simple_old.最近交易日期);*/
                                    
                                        this.custom_simpleTableAdapter.Fill(this.futuresTradeDataSet.custom_simple);
分不多 大拿们帮下忙

解决方案 »

  1.   

    同意匹配不到的可能性,先试试select看看有没有返回结果?
      

  2.   

    先把你的sql语句拿出来直接运行一下,看看能否update成功。怀疑update语句没有匹配的项因此更新失败
      

  3.   

    用中文是省得标注 烦人曲线救国了 结账 应该是匹配的问题 现在的表内所有字段设计成文本了。以前又是双精又是float 又是日期懒得去查bug点出在哪里了。还好数据库不大 处理起来问题不大