Click here to Skip to main content
15,884,099 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I searched on google but I couldn't get the right answer for my project..
I create a form in which i want to Insert,update and delete the records through the dataGridView..

My code is:-
C#
public partial class orderListDetails : Form
    {
        Data_Conn DC;
        string DelValue = string.Empty;
        public orderListDetails()
        {
            InitializeComponent();
            DC = new Data_Conn(Application.StartupPath);                       
        }

        private void orderListDetails_Load(object sender, EventArgs e)
        {
            DC.SelectSta("select proName as Name,proComp as Company,proQty as Qty,proUnit as Unit from orderList", "orderList");
            dataGridView1.DataSource = DC.dataSet;
            dataGridView1.DataMember = "orderList";
            
        }

        private void button5_Click(object sender, EventArgs e)
        {
            this.Dispose();
        }

        private void btnAddNew_Click(object sender, EventArgs e)
        {

           
            DC.CmdStatement("insert into orderList values('" + textBox1.Text + "','" + comboBox1.Text + "'," + Convert.ToInt32(textBox2.Text) + ",'" + comboBox2.Text + "')");
            
            DC.SelectSta("select proName as Name,proComp as Company,proQty as Qty,proUnit as Unit from orderList", "orderList");
            dataGridView1.DataSource = DC.dataSet;
            dataGridView1.DataMember = "orderList";
            dataGridView1.Refresh();    
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                
                DialogResult dr = MessageBox.Show("Do You want to delete the product details?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
                if (dr == DialogResult.Yes)
                {
                    dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index);
                    DC.CmdStatement("delete from orderList where proName='"+DelValue+"'");                    
                    DC.SelectSta("select proName as Name,proComp as Company,proQty as Qty,proUnit as Unit from orderList", "orderList");
                    dataGridView1.DataSource = DC.dataSet;
                    dataGridView1.DataMember = "orderList";                   
                }
            }
            catch
            { }
        }
        private void btnUpdate_Click(object sender, EventArgs e)
        {
            DC.adpt.Update(DC.dataSet, "orderList");
        }

        private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {                                                            
            DelValue = dataGridView1[0, e.RowIndex].Value.ToString();                          
        }
    }


when i click on Update button Its shows the error message
Update requires a valid UpdateCommand when passed DataRow collection with modified rows.


How to Update that record in database??

thanks in Advance....
Posted
Comments
[no name] 28-Mar-13 10:02am    
You write an UPDATE statement....
Richard C Bishop 28-Mar-13 10:18am    
You get my 5, I credited you for the solution to get it off the unanswered list.
Prasad Khandekar 28-Mar-13 10:26am    
My 5 as well.

As ThePhantomUpvoter so eloquently put it, you must write an Update statement in order to update a database. Ther are countless examples of them online.
 
Share this answer
 
You need to use the OleDbCommandBuilder as described in this example[^].
 
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