C # DataGridView Üzerinden Ekle, Update, Silme İşlemi
Çarşamba, 25 Oca 2012
yorum yok
DataGridView kontrolü Nokta Net Framework en ilgi çekici özelliklerinden biridir. Windows Form Sihirbazı veya program kullanarak bu kontrolü kullanabilirsiniz.
Bir form üzerinde bir DataGridView kontrolü ve iki Button ekleyin. Bir Düğme seçili satır silme ve diğer bir güncelleştirme veya yeni bir satır eklemek için.
Aşağıda gösterildiği gibi bu değişkenler bildirin.
public partial class DataTrialForm: Form
{
private String connectionString = null;
özel SqlConnection sqlConnection = null;
özel SqlDataAdapter SqlDataAdapter = null;
özel SqlCommandBuilder SqlCommandBuilder = null;
private DataTable = null;
özel BindingSource BindingSource = null;
private String selectQueryString = null;
kamu DataTrialForm ()
{
InitializeComponent ();
}
private void DataTraiForm_Load (object sender, EventArgs e)
{
connectionString = ConfigurationManager.AppSettings ["connectionString"];
sqlConnection = new SqlConnection (connectionString);
selectQueryString = "t_Bill DAN SELECT *";
SQLConnection.open ();
SqlDataAdapter = new SqlDataAdapter ( selectQueryString, sqlConnection);
SqlCommandBuilder = new SqlCommandBuilder (SqlDataAdapter);
DataTable = new DataTable ();
sqlDataAdapter.Fill (DataTable);
BindingSource = new BindingSource ();
= datatable bindingSource.DataSource;
dataGridViewTrial.DataSource = BindingSource; / / eğer Kimlik sütunu gizlemek için istediğiniz
dataGridViewTrial.Columns [0] Visible = false;
}
private void addUpadateButton_Click (object sender, EventArgs e)
{
try
{
sqlDataAdapter.Update (DataTable);
}
catch (Exception exceptionObj)
{
MessageBox.Show (exceptionObj.Message.ToString ());
} }
private void deleteButton_Click (object sender, EventArgs
(İstisna exceptionObj)
{
MessageBox.Show (exceptionObj.Message.ToString ());
}
}
- Bugün Okunma Sayısı :0 - Toplam Okunma Sayısı :1