Click here to Skip to main content
14,494,339 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hi,

In button click i populated gridview (no primary key for columns in database), using dataAdapter,dataset.

when i select a cell , that record should come in textboxes for editing data, after editing that should be saved in database.

edit button should be in gridview cell at the end of columns of database how to do.....

here is my code:
<pre lang="c#">using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using System.Data.OleDb;
using System.Text.RegularExpressions;

namespace Billling_Machine
{
    public partial class EditTransaction : Form
    {

        String ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString;
        DataSet ds = new DataSet();
        MySqlDataAdapter da;
        MySqlCommandBuilder commandbuilder;
        String query;

        public EditTransaction()
        {
            InitializeComponent();
        }

        private void btnedittxok_Click(object sender, EventArgs e)
        {
            String date1 = dateTimePicker1.Text;
            String[] date = Regex.Split(date1, "[/: ]");
            StringBuilder sb = new StringBuilder();
            sb.Append(date[2]);
            sb.Append("-");
            sb.Append(date[0]);
            sb.Append("-");
            sb.Append(date[1]);
            String fromdate = sb.ToString();


            String date2 = dateTimePicker2.Text;
            String[] date3 = Regex.Split(date2, "[/: ]");
            StringBuilder sb1 = new StringBuilder();
            sb1.Append(date3[2]);
            sb1.Append("-");
            sb1.Append(date3[0]);
            sb1.Append("-");
            sb1.Append(date3[1]);
            String todate = sb1.ToString();
            
            String customer = txtedittxcustomer.Text;
            String card = txtedittxcard.Text;


            using (MySqlConnection con = new MySqlConnection(ConnectionString))
            {
                query = "select * from transaction where DATE(paid_date)BETWEEN '" + fromdate + "'AND'" + todate + "' AND customer_id='" + customer + "' ";
                con.Open();
               da = new MySqlDataAdapter(query, con);
                         
             da.Fill(ds);
             dataGridView1.DataSource = ds;
             dataGridView1.DataMember = ds.Tables[0].ToString();
             DataGridViewButtonColumn ButtonColumn = new
DataGridViewButtonColumn();
             ButtonColumn.Text = "Edit";
             ButtonColumn.Name = "Edit";
             ButtonColumn.DataPropertyName = "del";
             dataGridView1.Columns.Add(ButtonColumn);

            
            }
            groupBox2.Visible = true;

        }

        private void EditTransaction_Load(object sender, EventArgs e)
        {
            groupBox2.Visible = false;
        }
Posted

1 solution

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




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