数据Adapter.update没有反映任何结果.是什么原因? [英] Data Adapter.update reflects no results. what is the reason?

查看:98
本文介绍了数据Adapter.update没有反映任何结果.是什么原因?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

public bool udf_uploadDataBase(DataSet Datasource)
    {
        bool status = true;
        DataSet ds = null;
        foreach (DataTable dt in Datasource.Tables)
        {
            try
            {
                udf_ConfigureServer("VIGNA-16", "sa", "vigna123!@#");
                ds = new DataSet();
                DataTable tmp = new DataTable();
                ds = new DataSet();
                ad = new SqlDataAdapter(); //client
                ad.SelectCommand = new SqlCommand("select * from " + dt.TableName + "", con);
                SqlCommandBuilder cb = new SqlCommandBuilder(ad);
                ad.Fill(ds);
                ad.UpdateCommand = cb.GetUpdateCommand();
                ad.InsertCommand = cb.GetInsertCommand();
                ad.DeleteCommand = cb.GetDeleteCommand();
                ad.AcceptChangesDuringUpdate = true;
                ad.FillLoadOption = LoadOption.OverwriteChanges;

                int rc = ad.Update(dt);
                ad.Update(Datasource.Tables[dt.TableName].Select(null,null,DataViewRowState.Added));
                ad.Update(Datasource.Tables[dt.TableName].Select(null, null, DataViewRowState.ModifiedCurrent));
                ad.Update(Datasource.Tables[dt.TableName].Select(null, null, DataViewRowState.Deleted));
                tmp.AcceptChanges();
                status = true;
                if (ds != null)
                    ds.Tables.Clear();
            }
            catch (Exception ex)
            {
                status = false;
            }
            finally
            {
                con.Close();
            }
        }
        return status;
    }





上面的代码是我编写的一个示例,该示例用于更新另一台服务器上的数据库,该数据库具有我在DataSet" Datasource "函数参数中获得的相同表.

我希望这段代码没有错误.我执行它时没有发现更多异常.但是目标数据库尚未更新.为什么?是什么原因?

请帮忙.





The above code is a sample that i ve written to update a database on another server with the same tables that i got in the DataSet "Datasource" the function argument.

I hope, this code has no bugs. i found no more exceptions when i executed it. But the target database hadn''t updated. why? what is the reason?

Kindly help.

推荐答案

我认为您正在使它变得比所需的复杂得多.您真的不必更新三遍.
我认为您只想将SQLDataAdapter上的DataSource设置为已解析的dataSource,然后进行直接更新即可,例如

I think you are making it much more complicated than you need to. You really shouldn''t have to update three times.
I think you want to just set the DataSource on your SQLDataAdapter to the parmed dataSource, and then do a straight update...something like

da.DataSource = dataSource;
da.Update();



除非您尝试做一些不同的事情,否则在这种情况下,请编辑您的问题以包括您要完成的任务.



Unless you are trying to do something a little different, in which case please edit your question to include exactly what you are trying to accomplish.


这篇关于数据Adapter.update没有反映任何结果.是什么原因?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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