如何使用csharp将搜索记录更新到数据库中 [英] how to update the search record into the data base using csharp

查看:103
本文介绍了如何使用csharp将搜索记录更新到数据库中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

运行模式下的四个字段如下;

Four Fields as follows in run mode;

Course Code     textbox
Course Name     textbox
course duration textbox
Allocated hours textbox





Threee按钮如下;



Threee button as follows;

Save  Search  Update



1.保存代码如下;


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.搜索代码如下;


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点击代码如下;


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();

     }



当我点击datagridveiw时,相应的条目将显示在文本框中。

,工作正常。



i想要更新课程持续时间和分配时间。

更新按钮中的内容我怎么能使用c sharp。



更新按钮。


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.

        }



请帮帮我。



如何编写代码更新课程持续时间和分配时间。



问候和谢谢。

Narasiman P.


please help me.

how can i write the code to update the course duration and allocated hours.

Regards and Thanks.
Narasiman P.

推荐答案

有什么问题?您所需要的只是使用ADO.NET编写更新查询

以下文章将帮助您了解:使用C#读取,插入,更新和删除简单的ADO.NET数据库。 [ ^ ]



试试!
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!


这篇关于如何使用csharp将搜索记录更新到数据库中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆