簡體   English   中英

無法弄清楚我的 insert into 語句將 windows forms 文本框的數據插入 ms access 數據庫中的一行有什么問題

[英]Can't figure out what's wrong with my insert into statement to insert data from a windows forms textbox to a row in ms access database

public partial class Form1 : Form
{
    static OleDbConnection con = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=chessclub.accdb");

    static OleDbCommand cmd = con.CreateCommand();
    static OleDbDataReader reader;
    int count = 0;
    
    public Form1()
    {
        InitializeComponent();
    }

    private void btncreate_Click(object sender, EventArgs e)
    {
        if (con.State.Equals(System.Data.ConnectionState.Open))
            con.Close();

        con.Open();

        OleDbCommand cmd = con.CreateCommand();
        cmd.CommandText = "INSERT INTO chess1db( names , schoolid , major , gender) + VALUES ( '" + txtname.Text + "','" + txtid.Text + "','" + txtmajor.Text + "','" + txtgndr.Text + "')";
        cmd.Connection = con;

        cmd.ExecuteNonQuery();

        MessageBox.Show("Record submitted ");
        con.Close();
    }
}

每次我按下按鈕將數據發送到數據庫時,它都會告訴我INSERT INTO語句中存在語法錯誤。 它出什么問題了?

這是加號。 去掉它:

cmd.CommandText = "INSERT INTO chess1db( names , schoolid , major , gender)  VALUES ('" + txtname.Text + "','" + txtid.Text + "','" + txtmajor.Text + "','" + txtgndr.Text + "')";

但是不要使用參數

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM