Wil Youmans

Wil Youmans

  • NA
  • 25
  • 0

Last record won't delete on dataset

Apr 6 2011 4:44 PM
Hi I cannot get my last record to delete from the database, unless I go back to the edit page and delete it again.
I am using tableadapters and c#.

             SqlCeConnection sc = new SqlCeConnection();

             string clientID = clientsDataSet1.ClientNames[0]["ClientID",  DataRowVersion.Original].ToString();

             int x = Int32.Parse(clientID);

            try

            {


                sc.ConnectionString = Properties.Settings.Default.ClientsConnectionString;


                //SqlCeCommand cmd = new System.Data.SqlServerCe.SqlCeCommand("INSERT INTO ClientTimes (ClientID) Values(" + row[0] + ")                 where not exist (select clientID from ClientNames where ClientID = " + row[0] + ");", sc);

               // string fullName = String.Concat(tbFirstName.Text, " ", tbLastName.Text);

                //string sqlCmd2 = "UPDATE ClientNames (ClientID, [First Name], [Last Name], [Full Name]) " +

                //    "Values(@ClientID,@FirstName,@LastName, @FullName);";

                string sqlCmd3 = "DELETE FROM ClientNames WHERE ClientID = @ClientID;";


                SqlCeParameter ParamClientID = new SqlCeParameter("ClientID", SqlDbType.Int);

              

                ParamClientID.Value = x;


                SqlCeCommand cmd2 = new SqlCeCommand(sqlCmd3, sc);

 

                cmd2.Parameters.Add(ParamClientID);


                sc.Open();

                cmd2.ExecuteNonQuery();

                sc.Close();

                dataGridView1.DataSource = null;

                dataGridView1.DataSource = clientsDataSet1.ClientNames;

              

             

            }


            catch (Exception ex)

            {

                MessageBox.Show(ex.ToString());

            }

            finally

            {

                sc.Close();

                                }

All record/rows delete but the last one.

Answers (2)