S.Y. ApArAn
Hectopat
- Katılım
- 13 Nisan 2020
- Mesajlar
- 5
Veri tabanı bağlamaya çalışırken ınsert ınto söz dizimi hatası alıyorum. Yardımcı olursanız sevinirim.
Kod:
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 WindowsFormsApp2
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OleDbConnection BAGLANTI = new OleDbConnection("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = C:\\Users\\Sadık Yiğithan\\Desktop\\proje.mdb");
private void verilerigörüntüle()
{
listView1.Items.Clear();
BAGLANTI.Open();
OleDbCommand komut = new OleDbCommand();
komut.Connection = BAGLANTI;
komut.CommandText=("select * from Tablo1");
OleDbDataReader oku = komut.ExecuteReader();
while(oku.Read())
{
[CODE]System.InvalidOperationException: 'ExecuteNonQuery: Connection özelliği başlatılmamış.' hatasını alıyorum
ListViewItem ekle = new ListViewItem();
ekle.Text = oku["İSİM"].ToString();
ekle.SubItems.Add(oku["SOYİSİM"].ToString());
ekle.SubItems.Add(oku["TC KİMLİK NO"].ToString());
ekle.SubItems.Add(oku["İLÇE"].ToString());
ekle.SubItems.Add(oku["YEMEK"].ToString());
ekle.SubItems.Add(oku["TARİHİ ESER"].ToString());
listView1.Items.Add(ekle);
}
BAGLANTI.Close();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
if (comboBox1.Text == "Ayancık")
{
comboBox2.Items.Clear();
comboBox2.Items.Add("Sinop mantısı");
}
if (comboBox1.Text == "Saraydüzü")
{
comboBox2.Items.Clear();
comboBox2.Items.Add("mısır çorbası");
}
if (comboBox1.Text == "Gerze")
{
comboBox2.Items.Clear();
comboBox2.Items.Add("nokul");
}
if (comboBox1.Text == "Erfelek")
{
comboBox2.Items.Clear();
comboBox2.Items.Add("katlama");
}
if (comboBox1.Text == "Durağan")
{
comboBox2.Items.Clear();
comboBox2.Items.Add("içli tava");
}
if (comboBox1.Text == "Dikmen")
{
comboBox2.Items.Clear();
comboBox2.Items.Add("ıslama");
}
if (comboBox1.Text == "Dikmen")
{
comboBox2.Items.Clear();
comboBox2.Items.Add("sirkeli pırasa");
if (comboBox1.Text == "Boyabat")
{
comboBox2.Items.Clear();
comboBox2.Items.Add("palamut pilaki");
}
if (comboBox1.Text == "Ayancık")
{
comboBox2.Items.Clear();
comboBox2.Items.Add("keşkek");
}
//--------------------------------------
else if (comboBox1.Text == "Ayancık")
{
comboBox3.Items.Clear();
comboBox3.Items.Add("Alaeddin Camii");
}
else if (comboBox1.Text == "Saraydüzü")
{
comboBox3.Items.Clear();
comboBox3.Items.Add("Sinop Kalesi");
}
else if (comboBox1.Text == "Gerze")
{
comboBox3.Items.Clear();
comboBox3.Items.Add("Sinop Pervane Medresesi");
}
else if (comboBox1.Text == "Erfelek")
{
comboBox3.Items.Clear();
comboBox3.Items.Add("Balatlar Kilisesi");
}
else if (comboBox1.Text == "Durağan")
{
comboBox3.Items.Clear();
comboBox3.Items.Add("Salar Köyü Kaya Mezarları");
}
else if (comboBox1.Text == "Dikmen")
{
comboBox3.Items.Clear();
comboBox3.Items.Add("Sinop Müzesi");
}
else if (comboBox1.Text == "Dikmen")
{
comboBox3.Items.Clear();
comboBox3.Items.Add("Diyojen Heykeli");
}
else if (comboBox1.Text == "Boyabat")
{
comboBox3.Items.Clear();
comboBox3.Items.Add("İnceburun Feneri");
}
else if (comboBox1.Text == "Ayancık")
{
comboBox2.Items.Clear();
comboBox3.Items.Add("Alaeddin Camii");
}
}
}
private void button2_Click(object sender, EventArgs e)
{
BAGLANTI.Open();
OleDbCommand komut = new OleDbCommand("insert into Tablo1 (İSİM,SOYİSİM,TC KİMLİK NO,İLÇE,YEMEK,TARİHİ ESER) values ('" + textBox1.Text + "','" + textBox2.Text + "','" + textBox3.Text + "','" + comboBox1.Text + "','" + comboBox2.Text + "','" + comboBox3.Text + "'",BAGLANTI);
komut.ExecuteNonQuery();
BAGLANTI.Close();
verilerigörüntüle();
}
private void button1_Click(object sender, EventArgs e)
{
verilerigörüntüle();
}
}
}
Dosya Ekleri
Son düzenleyen: Moderatör: