Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. problem in DELETING rows from gridview and database table using a check box column and a DELETE button.

problem in DELETING rows from gridview and database table using a check box column and a DELETE button.

Scheduled Pinned Locked Moved C#
databasehelpcsharplinqcom
3 Posts 3 Posters 1 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • O Offline
    O Offline
    Omar Akhtar Sheikh
    wrote on last edited by
    #1

    First of all when I select multiple rows to delete then it gives me an error: "Uncomitted new rows cannot be deleted." Secondly, if I select only one row at a time and click the delete button then it deletes all the rows from the database table. [code] using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Data.SqlClient; using System.Data.Sql; using Dotnet67.Sales.DAL; using Dotnet67.Sales.Items; using Dotnet67.Sales.Persons; using System.Data.SqlClient; namespace Dotnet67.Sales.DAL {       public class DALHelper       {             private readonly string CONSTRING3 = "CASHIER1";             private readonly string CONSTRING5 = "DELETE1";             //   THE FOLLOWING IS THE CODE WHERE I GET ERRORS             public void DeleteUser(int id)             {                   SqlTransaction tran = con.BeginTransaction();                   SqlConnection con = new SqlConnection("server=.; Database=Dotnet67;uid=sa;pwd=123;");                   SqlCommand com = new SqlCommand(CONSTRING5, con);                   com.CommandType = CommandType.StoredProcedure;                   com.Parameters.AddWithValue("@CashierID", id);                                     con.Open();                   com.ExecuteNonQuery();                   con.Close();             }             public void InsertIntoCashier(string[] str,int[] val)             {                   SqlConnection con = new SqlConnection("server=.; Database=Dotnet67;uid=sa;pwd=123;");     &nbs

    A S 2 Replies Last reply
    0
    • O Omar Akhtar Sheikh

      First of all when I select multiple rows to delete then it gives me an error: "Uncomitted new rows cannot be deleted." Secondly, if I select only one row at a time and click the delete button then it deletes all the rows from the database table. [code] using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Data.SqlClient; using System.Data.Sql; using Dotnet67.Sales.DAL; using Dotnet67.Sales.Items; using Dotnet67.Sales.Persons; using System.Data.SqlClient; namespace Dotnet67.Sales.DAL {       public class DALHelper       {             private readonly string CONSTRING3 = "CASHIER1";             private readonly string CONSTRING5 = "DELETE1";             //   THE FOLLOWING IS THE CODE WHERE I GET ERRORS             public void DeleteUser(int id)             {                   SqlTransaction tran = con.BeginTransaction();                   SqlConnection con = new SqlConnection("server=.; Database=Dotnet67;uid=sa;pwd=123;");                   SqlCommand com = new SqlCommand(CONSTRING5, con);                   com.CommandType = CommandType.StoredProcedure;                   com.Parameters.AddWithValue("@CashierID", id);                                     con.Open();                   com.ExecuteNonQuery();                   con.Close();             }             public void InsertIntoCashier(string[] str,int[] val)             {                   SqlConnection con = new SqlConnection("server=.; Database=Dotnet67;uid=sa;pwd=123;");     &nbs

      A Offline
      A Offline
      Abhijit Jana
      wrote on last edited by
      #2

      Omar Akhtar Sheikh wrote:

      First of all when I select multiple rows to delete then it gives me an error: "Uncomitted new rows cannot be deleted."

      It is becuase, you are trying to delete one row which is in Edit mode and not comitted with DB.

      Omar Akhtar Sheikh wrote:

      dataGridView1.Rows.RemoveAt(rowIndex);

      You just try to implement this.

      if (!dataGridView1.Rows[i].IsNewRow)
      // Remove here

      Note : Please make sure, while post code , please post it with proper format. Otherwise it really make difficult to read and understand. :-D

      Abhijit Jana | Codeproject MVP Web Site : abhijitjana.net Don't forget to click "Good Answer" on the post(s) that helped you.

      1 Reply Last reply
      0
      • O Omar Akhtar Sheikh

        First of all when I select multiple rows to delete then it gives me an error: "Uncomitted new rows cannot be deleted." Secondly, if I select only one row at a time and click the delete button then it deletes all the rows from the database table. [code] using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Data; using System.Data.SqlClient; using System.Data.Sql; using Dotnet67.Sales.DAL; using Dotnet67.Sales.Items; using Dotnet67.Sales.Persons; using System.Data.SqlClient; namespace Dotnet67.Sales.DAL {       public class DALHelper       {             private readonly string CONSTRING3 = "CASHIER1";             private readonly string CONSTRING5 = "DELETE1";             //   THE FOLLOWING IS THE CODE WHERE I GET ERRORS             public void DeleteUser(int id)             {                   SqlTransaction tran = con.BeginTransaction();                   SqlConnection con = new SqlConnection("server=.; Database=Dotnet67;uid=sa;pwd=123;");                   SqlCommand com = new SqlCommand(CONSTRING5, con);                   com.CommandType = CommandType.StoredProcedure;                   com.Parameters.AddWithValue("@CashierID", id);                                     con.Open();                   com.ExecuteNonQuery();                   con.Close();             }             public void InsertIntoCashier(string[] str,int[] val)             {                   SqlConnection con = new SqlConnection("server=.; Database=Dotnet67;uid=sa;pwd=123;");     &nbs

        S Offline
        S Offline
        SilimSayo
        wrote on last edited by
        #3

        You have SqlTransaction tran = con.BeginTransaction(); but no commit statement.... that may not be exactly the reason why your code fails but it is odd that you have BeginTransaction without CommitTransaction or Rollback. Secondly, after doing edits to the datagrid, unless you save changes to database, you can't delete them from the database. You can only remove them from the data grid

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups