我在C#Visual Studio 2017中制作会计项目,我有三种形式:
第1和第2表单正常工作,但是当我点击产品条目(第3表格)的按钮时, 项目没有进入第三种形式,它显示了这个错误:
System.Data.OleDb.OleDbException:'无效的SQL语句;预期 '删除',' INSERT','程序',' SELECT'或者'更新'。'
我的代码是:
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;
using System.Configuration;
using MetroFramework;
namespace MAARS_Software.Project
{
public partial class frmProductEntry : MetroFramework.Forms.MetroForm
{
OleDbConnection con = new
OleDbConnection(ConfigurationManager.AppSettings["con"]);
OleDbConnection conn = new
OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data
Source=D:\Backup\OneDrive\Documents\Visual Studio 2017\My
Projects\Backups\MAARS Software\DataBase.accdb;
Jet OLEDB: Database Password = 654321");
public frmProductEntry()
{
InitializeComponent();
}
private void frmProductEntry_Load(object sender, EventArgs e)
{
ViewData();
}
private void Save_btn_Click(object sender, EventArgs e)
{
}
private void Update_btn_Click(object sender, EventArgs e)
{
}
private void Delete_btn_Click(object sender, EventArgs e)
{
}
private void Exit_btn_Click(object sender, EventArgs e)
{
}
void ViewData()
{
OleDbDataAdapter da = new OleDbDataAdapter("Selct * from [Product]",
con);
//DataTable dt = new DataTable();
//da.Fill(dt);
DataSet ds = new DataSet();
da.Fill(ds); //Error stop here
dataGridView1.DataSource = ds.Tables[0];
}
}
}
答案 0 :(得分:0)
select
中OleDbDataAdapter da = new OleDbDataAdapter("Selct * from [Product]", con);
的错误字
应该像OleDbDataAdapter da = new OleDbDataAdapter("Select * from [Product]", con);