Click here to Skip to main content
15,923,142 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;
C#
      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;
C#
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;
C#
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.
C#
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
Updated 14-Feb-13 2:00am
v2

1 solution

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!
 
Share this answer
 
Comments
[no name] 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 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)



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