C# 无法获取要填充的数据表,因为;da.填充(dt)&引用;不工作。请帮忙,有作业吗
这是我的密码C# 无法获取要填充的数据表,因为;da.填充(dt)&引用;不工作。请帮忙,有作业吗,c#,syntax-error,C#,Syntax Error,这是我的密码 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; nam
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 SDD_Single_Project___Michael
{
public partial class AllData : Form
{
private OleDbConnection connection = new OleDbConnection();
public AllData()
{
InitializeComponent();
connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=G:\schoolwork\Year 11\SDD\3 SINGLE TASK\SDD Single Project - Michael \SDD Single Project - Michael \bin\Persondata.accdb;
Persist Security Info=False;";
}
private void btnBack_Click(object sender, EventArgs e)
{
this.Hide(); //hides this page
MainScreen frm = new MainScreen(); //finds the next screen (the main game)
frm.Show(); //shows it
}
private void btnShow_Click(object sender, EventArgs e)
{
try
{
connection.Open(); //opens connection
OleDbCommand command = new OleDbCommand(); //declare our object of oleDB command
command.Connection = connection; // the connection is giving to the command
string query = "select * Persondata";
command.CommandText = query; // pass the query to the command
OleDbDataAdapter da = new OleDbDataAdapter(command);
DataTable dt = new DataTable();
da.Fill(dt); // the error supposedly occurs here!!
dataGridView1.DataSource = dt;
connection.Close(); // closes the connection
}
catch (Exception ex)
{
MessageBox.Show("Error " + ex);
}
}
}
}
当我试着运行这个程序时,我得到的错误代码是,在第46行的“*Persondata”处有语法错误(这是theda.Fill(dt);行),我无法理解它。请帮助其完成作业。此:
"select * Persondata"
一定是
"select * FROM Persondata"
请发布实际错误消息您的查询没有“from”关键字,它应该是“select*from Persondata”。另外,如果我是正确的,您正在从MS Access文件读取数据-尝试将表名放入[]([Persondata])。我非常确定这会引发异常,并且我非常确定异常已经在确切地告诉您出了什么问题。。。