我是新的C#
程序員,我在遵循YouTube上的教程的同時編寫了代碼,我想通過添加特徵。在System.Data.dll中發生未處理的System.Data.OleDb.OleDbException類型的異常
然而,當我運行該程序,我不斷收到一個錯誤:
An unhandled exception of type 'System.Data.OleDb.OleDbException' occurred in System.Data.dll
內部異常是:
Syntax error in INSERT INTO statement
我檢查和代碼似乎是正確的我。
我重新檢查Access文件中的所有列,並且所有列都拼寫正確。
這是我的代碼:
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 Biletotomasyon
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
OleDbConnection baglanti=new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:/Users/msi-nb/Documents/Visual Studio 2013/Projects/Biletotomasyon/YOLCU.accdb");
private void radioButton3_CheckedChanged(object sender, EventArgs e)
{
}
private void label7_Click(object sender, EventArgs e)
{
}
private void comboBox7_SelectedIndexChanged(object sender, EventArgs e)
{
}
private void button56_Click(object sender, EventArgs e)
{
baglanti.Open();
OleDbCommand komut=new OleDbCommand ("INSERT INTO YOLCU (SEFER SAYISI,GÜZERGAH,VARİŞ YERİ,TARİH,SAAT,PERON,AD SOYAD,KOLTUKNO,TAM BİLET ÜCRETİ,TC,IB SAYISI,TOPLAM ÜCRET,CİNSİYET,BİLET CİNSİ) values ('"+comboBox7.Text.ToString()+"','"+comboBox6.Text.ToString()+"','"+comboBox1.Text.ToString()+"','"+ dateTimePicker1.Text.ToString()+"','"+comboBox5.Text.ToString()+"','"+comboBox2.Text.ToString()+"','"+textBox1.Text.ToString()+"','"+comboBox4.Text.ToString()+"','"+comboBox3.Text.ToString()+"','"+textBox2.Text.ToString()+"','"+textBox3.Text.ToString()+"',,'"+textBox4.Text.ToString()+"','"+radioButton1.Text.ToString()+"','"+radioButton3.Text.ToString()+"')",baglanti);
komut.ExecuteNonQuery();
baglanti.Close();
}
}
}
問題是什麼?我該如何解決它?
你必須彼此相鄰的兩個逗號。 ','刪除其中一個。 – mjwills
[防止插入SQL注入]可能的重複(https://stackoverflow.com/questions/17818473/preventing-sql-injection-on-insert) – mjwills