Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#
Four Fields as follows in run mode;
 Course Code     textbox
 Course Name     textbox
 course duration textbox
 Allocated hours textbox
 
Threee button as follows;
Save  Search  Update
1. Save code as follows;
        private Globalfunction GFun = new Globalfunction();
        private string sql;
 
  private void Btn_Save_Click(object sender, EventArgs e)
        {
            
            sql = "insert into Tb_course_Details ([Course_Code],[Course_Name],[Course_Duration],[Allocated_Hours]) " + " values( ' " + txt_coursecode.Text + "','" + txt_coursename.Text + "', " + txt_courseduration.Text + "," + txt_Allochrs.Text + ")";
 
            try
            {
                GFun.error = "";
                GFun.InsertAccessData(sql);
                if (GFun.error.ToString() != "")
                {
                    MessageBox.Show(GFun.error.ToString(), "Error");
                    return;
                }
 
                GFun.OleDbcon.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString(), "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
2. Search code as follows;
private void Btn_Search_Click(object sender, EventArgs e)
        {
 
            try
            {
                GFun.BindAccessConn();
                sql = "select  * from Tb_course_Details  order by Course_Code";
                OleDbDataAdapter da = new OleDbDataAdapter(sql, GFun.OleDbcon);
                DataTable dt = new DataTable();
                da.Fill(dt);
                DGVCourseDetails.DataSource = dt;
            }
 
            catch (Exception ex1)
            {
                MessageBox.Show(ex1.ToString(), "Error", MessageBoxButtons.OK);
                return;
            }
        }
3. datagridviewcell click code as follows;
   private void DGVCourseDetails_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            txt_coursecode.ReadOnly = true;
            txt_coursecode.Text = DGVCourseDetails.Rows[e.RowIndex].Cells[0].Value.ToString();
            txt_coursename.Text = DGVCourseDetails.Rows[e.RowIndex].Cells[1].Value.ToString();
            txt_courseduration.Text = DGVCourseDetails.Rows[e.RowIndex].Cells[2].Value.ToString();
            txt_Allochrs.Text = DGVCourseDetails.Rows[e.RowIndex].Cells[3].Value.ToString();
            
        }
when i click the datagridveiw,the respective entries will be displayed in the textbox.
that is working fine.
 
i want to update the course duration and Allocated hours.
for that in the update button how can i do using c sharp.
 
Update Button.
private void Btn_Update_Click(object sender, EventArgs e)
        {
     
       In Update Button how can i write the code to update course duration and  Allocated hours.
 
        }
please help me.
 
how can i write the code to update the course duration and allocated hours.
 
Regards and Thanks.
Narasiman P.
Posted 14-Feb-13 2:36am
Edited 14-Feb-13 3:00am
v2

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

What is the issue? All you need is to write an update query using ADO.NET
Following article will help you learn: Simple ADO.NET Database Read, Insert, Update and Delete using C#.[^]
 
Try out!
  Permalink  
Comments
Member 8054539 at 14-Feb-13 8:33am
   
not to update the code using ADO.NET.
i want to write the Update Code using oledb
 
for that how can i update the code using csharp.
Sandeep Mewara at 14-Feb-13 8:57am
   
Read the link above and these too:
MSDN: ADO.NET[^]
MSDN: Accessing Data with ADO.NET[^]

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



Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 14 Feb 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100