Witam,
Proszę o pomoc w znalezieniu pliku, możliwości edytowania Delete w adapterze.
Witam,
Proszę o pomoc w znalezieniu pliku, możliwości edytowania Delete w adapterze.
A możesz zadać pytanie?
Gdzie można edytować DeleteCommand ?
Chodzi Ci o klasę SqlDataAdapter?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Xml;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace JKManager_V_0._2
{
public partial class czlonkowie : Form
{
public czlonkowie()
{
InitializeComponent();
}
private void czlonkowie_Load(object sender, EventArgs e)
{
this.dataGridView1.DataError += new DataGridViewDataErrorEventHandler(dataGridView1_DataError);
// TODO: This line of code loads data into the 'wIPDataSet.Czlonek' table. You can move, or remove it, as needed.
try
{
this.czlonekTableAdapter.Fill(this.wIPDataSet.Czlonek);
//MessageBox.Show("Admistracja Członkami");
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e)
{
try
{
if ((e.Exception) is FormatException)
{
DataGridView view = (DataGridView)sender;
view.Rows[e.RowIndex].ErrorText = "Błąd";
view.Rows[e.RowIndex].Cells[e.ColumnIndex].ErrorText = "Błąd";
e.ThrowException = false;
MessageBox.Show("Proszę uzupełnij poprawnie", "Uzupełnij Dane", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Krytyczny Błąd systemu");
MessageBox.Show("[email protected] \n GG: 2824726 \n Skype: m2824726", "Skonaktuj się z Administratorem");
}
}
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
}
private void bindingNavigatorMoveNextItem_Click(object sender, EventArgs e)
{
}
private void bindingNavigatorAddNewItem_Click(object sender, EventArgs e)
{
}
private void saveToolStripButton_Click(object sender, EventArgs e)
{
//czlonekTableAdapter.Update(wIPDataSet.Czlonek);
try
{
this.Validate();
this.czlonekBindingSource.EndEdit();
this.czlonekTableAdapter.Update(this.wIPDataSet.Czlonek);
MessageBox.Show("Baza pomyślnie zaaktualizowana");
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message, "Błąd Zapisu");
MessageBox.Show("[email protected] \n GG: 2824726 \n Skype: m2824726", "Skonaktuj się z Administratorem");
}
}
private void toxml_Click(object sender, EventArgs e)
{
//czlonekTableAdapter.Fill(wIPDataSet.Czlonek);
//wIPDataSet.Czlonek.WriteXml("C:\\Users\\Myxir\\Desktop\\books.xml",XmlWriteMode.WriteSchema);
XmlTextWriter textWriter = new XmlTextWriter("C:\\Users\\Myxir\\Desktop\\jeden\\books.xml",null);
textWriter.WriteStartDocument();
textWriter.WriteEndDocument();
textWriter.Close();
}
//czlonkowie.SqlCommand DeleteCommand = new SqlCommand("DELETE FROM Czlonek WHERE ID_Czlonka = @ID_Czlonka");
//System.Data.SqlClient.SqlCommand Delete = new System.Data.SqlClient.SqlCommand();
private void Delete(object sender, EventArgs e)
{
this.Validate();
this.czlonekBindingSource.EndEdit();
this.czlonekBindingSource.RemoveCurrent();
//this.czlonekTableAdapter.Adapter.DeleteCommand = new System.Data.SqlClient.SqlCommand("DELETE * FROM Customers WHERE ID_Czlonka = ?");
//SqlCommand command = new SqlCommand("DELETE FROM Customers WHERE ID_Czlonka = @ID_Czlonka");
D
}
}
}
Poprostu nie umiem napisać funkcji która by usuwała rekord z bazy danych.
Sprawa jest na tyle ciekawa ze chciałbym by po zaznaczeniu pola który jest zarazem kluczem głównym w DataGridView można było usunąć go z bazy.
Jak tutaj widać do usunięcia go z bindingSource, czyli z wyświetlania używam removeCurrent