本文介绍了如何在没有主键的情况下使用CommandBuilder更新数据库表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在没有主键的情况下使用commandbuilder更新数据库表.

我们尝试过这种尝试;

How to update database table using commandbuilder without having Primary Key.

We Tried this Attempt;

obj.con = obj.Class_DBConnection();
            OracleCommand cmd = new OracleCommand();
            string fromsrvno = "000000067334";
            string tosrvno = "000000067350";
            qryStr = "select distinct * from  test_m_srvdetail  where SDBM_SERVICE_NO between''" + fromsrvno + "'' and ''" + tosrvno + "''";
            //qryStr = "TEST_UP";
            //cmd.CommandType = CommandType.StoredProcedure;
            //cmd.CommandText = "TEST_UP";
            //cmd.Connection = obj.con;
            //cmd.Parameters.Add("v_refcur", OracleType.Cursor).Direction = ParameterDirection.Output;
            //da = new OracleDataAdapter(cmd);
            da = new OracleDataAdapter(qryStr, obj.con);
            build = new OracleCommandBuilder(da);
            da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
            ds = new DataSet();
            //ds = da.ReturnProviderSpecificTypes;
            //da.FillSchema(ds, SchemaType.Source, "test_m_srvdetail");
            //ds.Tables["test_m_srvdetail"].PrimaryKey = new DataColumn {ds.Tables["test_m_srvdetail"].Columns["SDBM_SERVICE_NO"]}
            //ds.Tables[0].PrimaryKey = ds.Tables[0].Columns[0];

            da.Fill(ds, "test_m_srvdetail");
            ds.Tables[0].Constraints.Add("pk_sid", ds.Tables[0].Columns["SDBM_SERVICE_NO"], true);
            ds.Tables[0].AcceptChanges();

           // da.FillSchema(ds, SchemaType.Source, "test_m_srvdetail");
            da.FillSchema(ds, SchemaType.Mapped, "test_m_srvdetail");
            da.Update(ds.Tables[0]);
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                ds.Tables[0].Rows[i]["SDBM_CURRENT_BILL_AMT"] = 1000;
                ds.Tables[0].Rows[i]["SDBM_BALANCE_BILL_AMT"] = 1000;
            }

            //ds.Tables[0].AcceptChanges();

            da.UpdateCommand = build.GetUpdateCommand();
            //OracleCommand updatecommnad = new OracleCommand();
            //updatecommnad.CommandText = "update table test_m_srvdetail  where SDBM_SERVICE_NO between''" + fromsrvno + "'' and ''" + tosrvno + "''";

            da.Update(ds.Tables[0]);



我们正在使用此错误:
不返回任何键列信息的SelectCommand不支持为UpdateCommand生成动态SQL.



We Are using this error:
Dynamic SQL generation for the UpdateCommand is not supported against a SelectCommand that does not return any key column information.

推荐答案



这篇关于如何在没有主键的情况下使用CommandBuilder更新数据库表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 12:21