Click here to Skip to main content
15,895,370 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
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]);


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.
Posted
Comments
Sandeep Mewara 29-Jul-10 12:27pm    
Well, I doubt that without Primary Key it would be possible. Let see if someone can suggest otherwise.
Prasad Bansi Vagal 2-Aug-10 13:01pm    
Reason for my vote of 5
coman deficult, read online ebooks on sql, .net, oops concept not so clear.

First of all data cannot be updated without using a primary key column, as it won't be posible to search for a pasticular data and to update it, it should be mandatory to have a primary key for atleast a column. :)
Prasad Vagal
 
Share this answer
 
Any other solution to do this.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900