No one is going to read that much unformatted code. Use
http://dotnetdevelopment.pastebin.com/ .

On Oct 20, 7:42 am, Paulo Hendler <[email protected]> wrote:
> Hello people
> I need to know how can I work a delete command from a table adapter. Follows
> my linnes:
>
> 1) A solution that contains win app and one class Library.
> 2) The Class Library (Slibrary) its refence to app (Smovieapp).
> 3) In the Class library theres a DataSet (SmartDS)
> 4) Build in a SQL Express 2005 table that follows:
>
> ID Nome   Linguagem Acervo Sinopse [Classificação] Assistido Genero 1 A
> proposta  Legendado 2 A arte do demônio  Dublado 3 A batalha de
> Riddick Dublado 4 A bolha assassina
>   Legendado 5 A bússola de ouro Dublado 6 A caçada Dublado 7 A cadeira do
> diabo  Dublado 8 A Caminho da Guerra  Dublado 9 A cartada final  Dublado 10
> A casa caiu  Dublado 11 A casa das coelhinhas  Dublado 12 A casa de vidro 2
> Dublado 13 A casa do lago  Dublado 14 A casa dos horrores  Dublado 15 A
> caverna Dublado Collum Name Data Type Allow Nulls           ID int Unchecked
>           Nome nvarchar(50) Unchecked           Linguagem nvarchar(50)
> Checked           Acervo nvarchar(50) Checked           Sinopse
> nvarchar(MAX) Checked           Classificação nvarchar(50) Checked
> Assistido nvarchar(50) Checked           Genero nvarchar(50) Checked
>
> 4b)The last blue part is the table definition all the fields isn't null just
> here. There's a default value = 'Editar'.
> 5) THeres an Inherit Form that the control call the data in a gridview an
> some text boxes, combo boxes.....
>
> All works perfectly, just the delete not,
>
> The delete control is a button follows the code:
>
> using System;
> using System.Collections.Generic;
> using System.ComponentModel;
> using System.Data;
> using System.Diagnostics;
> using System.Data.Common;
> using System.Data.SqlTypes;
> using System.Data.SqlClient;
> using System.Drawing;
> using System.IO;
> using System.Text;
> using System.Windows.Forms;
> using Slibrary;
> using Slibrary.SmartDSTableAdapters;
>
> namespace Smovieapp
> {
>     public partial class SmovieEditor : Smovieapp.FatherForm
>     {
>         //FilmotecaTableAdapter Morpheu;
>         SmartDS.FilmotecaDataTable Morpheu;
>         int Index;
>         SmartDS.FilmotecaDataTable MOrpheuRow;
>
>         public SmovieEditor()
>         {
>             InitializeComponent();
>         }
>
>         private void SmovieEditor_Load_1(object sender, EventArgs e)
>         {
>             // TODO: This line of code loads data into the
> 'sdataDataSetGrid.Filmoteca' table. You can move, or remove it, as needed.
>
>  this.filmotecaTableAdapter1.Fill(this.sdataDataSetGrid.Filmoteca);
> // TODO: This line of code loads data into the 'sdataDataSet.Filmoteca'
> table. You can move, or remove it, as needed.
> this.filmotecaTableAdapter.Fill(this.sdataDataSet.Filmoteca);
>
> #region [EVENTO LOAD>>>>> recuperando dados, populando]
>
>             FilmotecaTableAdapter adapter = new FilmotecaTableAdapter();
>             Morpheu = new SmartDS.FilmotecaDataTable();
>             MOrpheuRow = new SmartDS.FilmotecaDataTable();
>             adapter.Fill(Morpheu);
>             adapter.Dispose();
>             Index = 0;
>             ShowData();
>             // DataTable dtLista = new DataTable();
>             // dataGridView1.DataSource = Morpheu;
>             #endregion
>
>         }
>
>         #region [Chamado SHOW DATA]
>         private void ShowData()
>         {
>             if (Index < 0)
>                 Index = 0;
>             if (Index > Morpheu.Count - 1)
>                 Index = Morpheu.Count - 1;
>
>             txtCursorIndex1.Text = Index.ToString();
>             txtIDEdit.Text =
>                 Morpheu[Index].ID.ToString();
>
>             txtNomeEdit.Text =
>                 Morpheu[Index].Nome.Trim();
>             cbLinguagemEdit.Text =
>                 Morpheu[Index].Linguagem.Trim();
>             cbGeneroEdit.Text =
>                 Morpheu[Index].Genero.Trim();
>             cbClassificaçãoEdit.Text =
>                 Morpheu[Index].__Classificação_.Trim();
>             cbAssitidoEdit.Text =
>                 Morpheu[Index].Assistido.Trim();
>             rtxtSinopseEdit.Text =
>                 Morpheu[Index].Sinopse.Trim();
>             txtAcervoEdit.Text =
>                 Morpheu[Index].Acervo.Trim();
>
> }
>
>         #endregion
>
>         private void btnNext_Click(object sender, EventArgs e)
>         {
>             Index++;
>             ShowData();
>
>         }
>
>         private void btnFirst_Click(object sender, EventArgs e)
>         {
>             Index = 0;
>             ShowData();
>         }
>
>         private void btnPrevious_Click(object sender, EventArgs e)
>         {
>             Index--;
>             ShowData();
>
>         }
>
>         private void btnLast_Click(object sender, EventArgs e)
>         {
>             Index = Morpheu.Count - 1;
>             ShowData();
>         }
>
>         private void btnSel_Click(object sender, EventArgs e)
>         {
>
> FilmotecaTableAdapter da = new FilmotecaTableAdapter();
>
> da.Fill(Morpheu);
>             da.Dispose();
>             int valor = new int();
>             int valor2 = new int();
>             valor = Convert.ToInt32(label3.Text);
>             valor2 = valor - 1;
>             Index = valor2;
>
>             if (Index < 0)
>                 Index = valor2;
>             if (Index > Morpheu.Count + 1)
>                 Index = Morpheu.Count + 1;
>
>             txtCursorIndex1.Text = Index.ToString();
>             txtIDEdit.Text =
>                 Morpheu[Index].ID.ToString();
>
>             txtNomeEdit.Text =
>                 Morpheu[Index].Nome.Trim();
>             cbLinguagemEdit.Text =
>                 Morpheu[Index].Linguagem.Trim();
>             cbGeneroEdit.Text =
>                 Morpheu[Index].Genero.Trim();
>             cbClassificaçãoEdit.Text =
>                 Morpheu[Index].__Classificação_.Trim();
>             cbAssitidoEdit.Text =
>                 Morpheu[Index].Assistido.Trim();
>             rtxtSinopseEdit.Text =
>                 Morpheu[Index].Sinopse.Trim();
>             txtAcervoEdit.Text =
>                 Morpheu[Index].Acervo.Trim();
>         }
>
>         private void btnNew_Click(object sender, EventArgs e)
>         {
>             txtNomeEdit.Focus();
>             Index = Morpheu.Count;
>             txtCursorIndex1.Text = Index.ToString();
>             txtIDEdit.Text = "";
>             txtNomeEdit.Text = "";
>             cbLinguagemEdit.Text = "";
>             cbGeneroEdit.Text = "";
>             txtAcervoEdit.Text = "";
>             cbAssitidoEdit.Text = "";
>             rtxtSinopseEdit.Text = "";
>
>         }
>
>         private void btnSave_Click(object sender, EventArgs e)
>         {
>             if (txtNomeEdit.Text.Trim() == string.Empty)
>             {
>                 MessageBox.Show("Olha, o nome do filme deve ser
> preenchido...");
>                 return;
>             }
>             FilmotecaTableAdapter adapter = new FilmotecaTableAdapter();
>             if (Index == Morpheu.Count)
>                 adapter.Insert(txtNomeEdit.Text.Trim(),
> cbLinguagemEdit.Text.Trim(),
>                     txtAcervoEdit.Text.Trim(), rtxtSinopseEdit.Text.Trim(),
> cbClassificaçãoEdit.Text.Trim(),
>                         cbAssitidoEdit.Text.Trim(),
> cbGeneroEdit.Text.Trim());
>             else
>             {
>                 Morpheu[Index].Nome = txtNomeEdit.Text.Trim();
>                 Morpheu[Index].Linguagem = cbLinguagemEdit.Text.Trim();
>                 Morpheu[Index].Acervo = txtAcervoEdit.Text.Trim();
>                 Morpheu[Index].Sinopse = rtxtSinopseEdit.Text.Trim();
>                 Morpheu[Index].__Classificação_=
> cbClassificaçãoEdit.Text.Trim();
>                 Morpheu[Index].Assistido = cbAssitidoEdit.Text.Trim();
>                 Morpheu[Index].Genero = cbGeneroEdit.Text.Trim();
>                 adapter.Update(Morpheu[Index]);
>             }
>
>             Morpheu.Clear();
>             adapter.Fill(Morpheu);
>             adapter.Dispose();
>             ShowData();
>             dataGridView1.Refresh();
>             this.Refresh();
>             this.Hide();
>             this.Show();
>
>         }
> /*/ Here the not dele occurs!*
>         private void btnDelete_Click(object sender, EventArgs e)
>         {
>
>             int a = new int ();
>             a= Convert.ToInt32(txtCursorIndex1.Text);
>             Slibrary.SmartDSTableAdapters.FilmotecaTableAdapter filmotecaTA
> = new Slibrary.SmartDSTableAdapters.FilmotecaTableAdapter();
>
>             filmotecaTA.Delete(a,txtNomeEdit.Text.Trim(),
> cbLinguagemEdit.Text.Trim(),
>               txtAcervoEdit.Text.Trim(), cbClassificaçãoEdit.Text.Trim(),
> cbAssitidoEdit.Text.Trim(), cbGeneroEdit.Text.Trim(),
> rtxtSinopseEdit.Text.Trim());
>
>             Morpheu.Clear();
>             adapter.Fill(Morpheu);
>             adapter.Dispose();
>             ShowData();
>             dataGridView1.Refresh();
>             this.Refresh();
>             this.Hide();
>             this.Show();
>
>             //  FilmotecaTableAdapter deleter = new FilmotecaTableAdapter()
> ;
>                  //  MessageBox.Show("Ainda não conseguir fazer este
> controle funcionar corretamente");
>
>                   //
> deleter.DeleteQuery1(int.Parse(txtCursorIndex1.Text),
> txtNomeEdit.Text.Trim(), cbLinguagemEdit.Text.Trim(),
>                   //        txtAcervoEdit.Text.Trim(),
> cbClassificaçãoEdit.Text.Trim(),
>                    //         cbAssitidoEdit.Text.Trim(),
> cbGeneroEdit.Text.Trim(), rtxtSinopseEdit.Text.Trim());
>
>                  //  Morpheu.Clear();
>                   // deleter.Update(Morpheu);
>                  //  Morpheu[Index].Delete();
>                  //  deleter.Fill(Morpheu);
>                  //deleter.Dispose();
>                 //Index--;
>                // ShowData();
>                // dataGridView1.Refresh();
>                // this.Refresh();
>             }
>         }
>
> I Don´t Know how the save works and the delete not work.... I used the same
> logic.
>
> Some Help?
>
> Thank's
>
> *Appendix:*
>
> DeleteQuery:
> Deletequery1:
> or
> Delete:
>
> DELETE FROM Filmoteca
> WHERE     (ID = @Original_ID) AND (Nome = @Original_Nome) AND (Linguagem =
> @Original_Linguagem) AND (Acervo = @Original_Acervo) AND
>                       (Classificação = @Original_Classificação) AND
> (Assistido = @Original_Assistido) AND (Genero = @Original_Genero) AND
>                       (Sinopse = @Original_Sinopse)

Reply via email to