komkemkom
Kilopat
- Katılım
- 28 Ocak 2014
- Mesajlar
- 90
Ödev amaçlı teknik servis programı yazıyorum. Sürekli "Error CS0122 Form1.dataGridView1' is inaccessible due to its protection level" hatası veriyor. Yardımcı olur musunuz?
Kodum şu şekilde:
Kodum şu şekilde:
Kod:
Form1 kodum:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
namespace TeknikServis_Kayıt
{
public partial class Form1 : Form
{
public Form2 frm2;
public Form1()
{
InitializeComponent();
frm2 = new Form2();
frm2.frm1 = this;
}
OleDbConnection ziyahocaodevbaglantisi = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database.mdb");
DataTable tablo = new DataTable();
OleDbCommand komut = new OleDbCommand();
public void datacheck()
{
tablo.Clear();
OleDbDataAdapter adptr = new OleDbDataAdapter("Select * From Musteri", ziyahocaodevbaglantisi);
adptr.Fill(tablo);
dataGridView1.DataSource = tablo;
}
private void Form1_Load(object sender, EventArgs e)
{
txtadi.Focus();
datacheck();
dataGridView1.Columns[0].HeaderText = "Adı";
dataGridView1.Columns[1].HeaderText = "Soyadı";
dataGridView1.Columns[6].HeaderText = "Arıza";
}
private void button1_Click(object sender, EventArgs e)
{
try
{
ziyahocaodevbaglantisi.Open();
komut.Connection = ziyahocaodevbaglantisi;
komut.CommandText = "INSERT INTO Musteri(Adi,Soyadi,Tel,Adres,Marka,Model,Ariza,Fiyat,Tarih) VALUES('" + txtadi.Text + "','" + txtsoyadi.Text + "','" + txttel.Text + "','" + txtadres.Text + "','"
+ txtMarka.Text + "','" + txtModel.Text + "','" + txtArıza.Text + "','" + txtFiyat.Text +
"','" + dateTimePicker1.Value.ToShortDateString() + "')";
komut.ExecuteNonQuery();
ziyahocaodevbaglantisi.Close();
datacheck();
MessageBox.Show("Kayıt Ekleme İşlem Başarıyla Tamamlandı", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
catch (Exception)
{
MessageBox.Show("Aynı Kayıt Tekrar Eklenemez!");
ziyahocaodevbaglantisi.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
try
{
DialogResult cevap;
cevap = MessageBox.Show("Kaydı Silmek İstediğinizden Eminmisiniz?", "Uyarı", MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (cevap == DialogResult.Yes)
{
ziyahocaodevbaglantisi.Open();
komut.Connection = ziyahocaodevbaglantisi;
komut.CommandText = "Delete From Musteri Where Tel='" + dataGridView1.CurrentRow.Cells[2].Value.ToString() + "'";
komut.ExecuteNonQuery();
ziyahocaodevbaglantisi.Close();
datacheck();
MessageBox.Show("Silindi", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
}
catch (Exception)
{
MessageBox.Show("Hata!", "Uyarı");
}
}
private void button3_Click(object sender, EventArgs e)
{
frm2.ShowDialog();
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
}
}
Form2 kodum:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.OleDb;
namespace TeknikServis_Kayıt
{
public partial class Form2 : Form
{
public Form1 frm1;
public Form2()
{
InitializeComponent();
}
OleDbConnection ziyahocaodevbaglantisi = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database.mdb");
OleDbCommand komut = new OleDbCommand();
private void Form2_Load(object sender, EventArgs e)
{
try
{
txtAdi.Text = Form1.dataGridView1.CurrentRow.Cells[0].Value.ToString();
txtSoyadi.Text = frm1.dataGridView1.CurrentRow.Cells[1].Value.ToString();
txtTel.Text = frm1.dataGridView1.CurrentRow.Cells[2].Value.ToString();
txtAdres.Text = frm1.dataGridView1.CurrentRow.Cells[3].Value.ToString();
txtMarka.Text = frm1.dataGridView1.CurrentRow.Cells[4].Value.ToString();
txtMarka.Text = frm1.dataGridView1.CurrentRow.Cells[5].Value.ToString();
txtAriza.Text = frm1.dataGridView1.CurrentRow.Cells[6].Value.ToString();
txtMarka.Text = frm1.dataGridView1.CurrentRow.Cells[7].Value.ToString();
dateTimePicker1.Text = frm1.dataGridView1.CurrentRow.Cells[8].Value.ToString();
}
catch (Exception)
{
MessageBox.Show("Boş Kayıt Güncellenemez!", "Uyarı");
}
}
private void button1_Click(object sender, EventArgs e)
{
try
{
ziyahocaodevbaglantisi.Open();
komut.Connection = ziyahocaodevbaglantisi;
komut.CommandText = "update Musteri set Adi='" + txtAdi.Text + "',Soyadi='" + txtSoyadi.Text + "',Tel='" +
txtTel.Text + "',Adres='" + txtAdres.Text + "',Marka='" + txtMarka.Text + "',Model='" + txtModel.Text + "',Ariza='" + txtAriza.Text + "',Fiyat='"
+ txtFiyat.Text + "',Tarih='" + frm1.dataGridView1.CurrentRow.Cells[2].Value.ToString() + "'";
komut.ExecuteNonQuery();
ziyahocaodevbaglantisi.Close();
frm1.datacheck();
MessageBox.Show("Güncelleme İşlemi Tamamlandı", "Bilgi", MessageBoxButtons.OK, MessageBoxIcon.Information);
this.Close();
}
catch (Exception) {
MessageBox.Show("Güncelleme Yapılamadı", "Uyarı");
}
}
}
}
Son düzenleyen: Moderatör: