Click here to Skip to main content
15,892,517 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
string tbl = "ConfArticle";
            string sqlStr = string.Concat("SELECT * FROM ", tbl);

            try
            {
                OleDbConnection cnn = new OleDbConnection(cnnStr);
          OleDbDataAdapter oda = new OleDbDataAdapter(sqlStr, cnn);
                OleDbCommandBuilder ocb = new OleDbCommandBuilder(oda);
                 cnn.Open();
                OleDbCommand cmd = new OleDbCommand(sqlStr, cnn);
                OleDbDataReader drr = cmd.ExecuteReader();
                DataSet ds = new DataSet();
                DataTable dt = new DataTable();
                DataRow dr;
                ocb.QuotePrefix = "[";
                ocb.QuoteSuffix = "]";
                oda.Fill(ds, tbl);

                bool found = false;

                if (textBox2.Text.Trim() != id4edit.Trim())
                    while (drr.Read())
                    {
     if (drr["P_ID"].ToString().Trim() == textBox2.Text.Trim())
                        {
                            found = true;
                            break;
                        }
                    }

                if (!found)
                {
                    dt = ds.Tables[tbl];
                    for (int i = 0; i < dt.Rows.Count; ++i)
                    {
                        dr = dt.Rows[i];
    if (dr["P_ID"].ToString().Trim() == id4edit.Trim())
                        {
                            dr.BeginEdit();

                            dr["P_ID"] =    textBox2.Text.Trim();
                            dr["Art_Title"] = textBox6.Text.Trim();
                            dr["Reg_No"] =   textBox4.Text.Trim();

                            dr.EndEdit();

                            oda.UpdateCommand = ocb.GetUpdateCommand();

                            if (oda.Update(ds, tbl) == 1)
                            {
                                ds.AcceptChanges();
                                MessageBox.Show("Updated!!");
                            }
                            else
                            {
                                ds.RejectChanges();
                                MessageBox.Show("Rejected");
                            }

                            break;
                        }
                    }
                }
                else
                    MessageBox.Show("Duplicate Error");

                
                drr.Close();
                cnn.Close();

                dt.Dispose();
                ds.Dispose();
                drr.Dispose();
                cmd.Dispose();
                ocb.Dispose();
                oda.Dispose();
                cnn.Dispose();

                dt = null;
                ds = null;
                drr = null;
                cmd = null;
                ocb = null;
                oda = null;
                cnn = null;
            }
            catch (Exception ex)
            {
                MessageBox.Show("Error:\n\t" + ex.Message);
            }
            finally
            {
            }

i use this code for edit a data base but when i press edit button i see
this "Dynamic SQL generation for the UpdateCommand is not Supported againest a SelectCommand that does not return any key column information" error

please help me i need it
Posted
Updated 31-Jul-10 4:44am
v2

1 solution

The error message says that your SQL table has noch primary key set.
 
Share this answer
 
Comments
afshin.b.k 31-Jul-10 15:19pm    
Reason for my vote of 5
yhis man just amazing me
afshin.b.k 31-Jul-10 15:19pm    
thank u very much its work , i cant believe .

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