C# "System. Data. SqlClient. SqlException: 'Incorrect syntax near the keyword 'where'." hatası

Kroxxy

Hectopat
Katılım
31 Ocak 2019
Mesajlar
74
Daha fazla  
Cinsiyet
Erkek
Kod:
Private Void btnguncelle_Click(object sender, EventArgs e)
 {
 baglanti.Open();
 SqlCommand komut = New SqlCommand("Update müşteri set adsoyad=@adsoyad, telefon=@telefon, adres=@adres, email=@email, where T.C.=@tc", baglanti);
 Komut. Parameters. AddWithValue("@tc", txtTC. Text);
 Komut. Parameters. AddWithValue("[USER=431943]@adsoyad[/USER]", txtAdSoyad. Text);
 Komut. Parameters. AddWithValue("@telefon", txtTelefon. Text);
 Komut. Parameters. AddWithValue("@adres", txtAdres. Text);
 Komut. Parameters. AddWithValue("[USER=320013]@email[/USER]", txtEmail. Text);
 komut.ExecuteNonQuery();
 baglanti.Close();
 daset.Tables["müşteri"].Clear();
 Kayıt_Goster();
 MessageBox. Show("Müşteri Kaydı Güncellendi");
 Foreach (Control item in this. Controls)
 {
 İf (item is TextBox)
 {
 İtem. Text = "";
 }

 }
 }

Kod Bloğunda
System. Data. SqlClient. SqlException: 'Incorrect syntax near the keyword 'where'.' hatası alıyorum. Çözüm önerisi olan paylaşırsa sevinirim.
 
aglanti.Open();
SqlCommand komut = New SqlCommand("INSERT INTO hastakayit (Patient Name, Patient Surname, Patient Gender, Ulcerstage, Date of Entry, Age, Reason For Leaving, Bed No, Release Date) Values ( '" + NameTb. Text + "','" + SurnameTb. Text + "', '" + GenderTb. Text + "','" + UlcerstageTb. Text + "', @date of Entry,'" + AgeTb. Text + "','" + RvTb. Text + "','" + BednoTb. Text + "',@Release Date)", baglanti);

Komut. Parameters. AddWithValue("@date of Entry", DateTime. Now);
Komut. Parameters. AddWithValue("@Release Date", DateTime. Now);
komut.ExecuteNonQuery();
baglanti.Close(); //bağlantıyı kapa.
MessageBox. Show("kayıt eklendi");
listele();
Temizle();
komut.ExecuteNonQuery(); kısmına X işareti geliyor ve: 'Incorrect syntax near the keyword 'of'.
Incorrect syntax near 'Name'.'
Hatası alıyorum nasıl düzeltebilirim yardımcı olabilir misiniz?
 
aglanti.Open();
SqlCommand komut = New SqlCommand("INSERT INTO hastakayit (Patient Name, Patient Surname, Patient Gender, Ulcerstage, Date of Entry, Age, Reason For Leaving, Bed No, Release Date) Values ( '" + NameTb. Text + "','" + SurnameTb. Text + "', '" + GenderTb. Text + "','" + UlcerstageTb. Text + "', @date of Entry,'" + AgeTb. Text + "','" + RvTb. Text + "','" + BednoTb. Text + "',@Release Date)", baglanti);

Komut. Parameters. AddWithValue("@date of Entry", DateTime. Now);
Komut. Parameters. AddWithValue("@Release Date", DateTime. Now);
komut.ExecuteNonQuery();
baglanti.Close(); //bağlantıyı kapa.
MessageBox. Show("kayıt eklendi");
listele();
Temizle();
komut.ExecuteNonQuery(); kısmına X işareti geliyor ve: 'Incorrect syntax near the keyword 'of'.
Incorrect syntax near 'Name'.'
Hatası alıyorum nasıl düzeltebilirim yardımcı olabilir misiniz?
Patient Name gibi boşluk içeren kolon isimleri için [Patient Name] gibi bir şey kullanmanız lazım diye biliyorum, en iyisi Patient_Name gibi bir format kullanmak.
 
Where'den önceki virgülü silin.

Hocam buradaysanız bana da bir yardımcı olur musunuz lütfen?
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.SqlClient;
using Microsoft.Data.SqlClient;
using System.CodeDom;
namespace KanBankasıYönetimSistemi
{
    public partial class DonorListesi : Form
    {
        public DonorListesi()
        {
            InitializeComponent();
            uyeler();
        }
        SqlConnection baglanti = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Selami\Documents\KanBankasıYönetimSistemi.mdf;Integrated Security=True;Connect Timeout=30;Encrypt=True");
        private void uyeler()
        {
            baglanti.Open();
            string query = "select *from DonorTbl";
            SqlDataAdapter sda = new SqlDataAdapter(query, baglanti);
            SqlCommandBuilder builder = new SqlCommandBuilder(sda);
            var ds = new DataSet();
            sda.Fill(ds);
            DonorDGV.DataSource = ds.Tables[0];
            baglanti.Close();
        }
        private void DonorListesi_Load(object sender, EventArgs e)
        {

        }
    }
}
 
Hocam buradaysanız bana da bir yardımcı olur musunuz lütfen?
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.SqlClient;
using Microsoft.Data.SqlClient;
using System.CodeDom;
namespace KanBankasıYönetimSistemi
{
    public partial class DonorListesi : Form
    {
        public DonorListesi()
        {
            InitializeComponent();
            uyeler();
        }
        SqlConnection baglanti = new SqlConnection(@"Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=C:\Users\Selami\Documents\KanBankasıYönetimSistemi.mdf;Integrated Security=True;Connect Timeout=30;Encrypt=True");
        private void uyeler()
        {
            baglanti.Open();
            string query = "select *from DonorTbl";
            SqlDataAdapter sda = new SqlDataAdapter(query, baglanti);
            SqlCommandBuilder builder = new SqlCommandBuilder(sda);
            var ds = new DataSet();
            sda.Fill(ds);
            DonorDGV.DataSource = ds.Tables[0];
            baglanti.Close();
        }
        private void DonorListesi_Load(object sender, EventArgs e)
        {

        }
    }
}
select * from DonorTbl (* dan sonra bir boşluk bırakıp dener misiniz)
 

Geri
Yukarı