我是 C# 新手,我的项目需要帮助。请协助!
我想创建一个插入函数,允许我将数据插入到我的 MS Access DB 中。但是,我不断收到错误消息,指出语句末尾缺少分号 (;) 并且数据不会结束
下面是我的代码,
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace Insert
{
public partial class Form1 : Form
{
OleDbConnection vcon= new OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C://Database//HelloDB.accdb");
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
vcon.Open();
}
private void buttonExit_Click(object sender, EventArgs e)
{
this.Close();
}
private void buttonSave_Click(object sender, EventArgs e)
{
string ab = string.Format("insert into Hello values(id, 'Hname'))", int.Parse(textBox1.Text), textBox2.Text);
OleDbCommand vcom = new OleDbCommand(ab, vcon);
vcom.ExecuteNonQuery();
MessageBox.Show("Data stored successfully");
vcom.Dispose();
}
}