主题:[讨论]关于c#与access数据库连接时出现错误[求助]
偶的错误是提示我from子句语法错误....但我感觉那个select语句不可能错的啊...
下面的是我仿照连接sql2000数据库而改写的...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.OleDb;
namespace lianjiemdb
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
OleDbConnection mycn = new OleDbConnection();
mycn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "plzc.mdb";
OleDbCommand oledbCommand = new OleDbCommand();
oledbCommand.Connection = mycn;
oledbCommand.CommandType = CommandType.Text;
oledbCommand.CommandText = "SELECT * FROM user";
mycn.Open();
OleDbDataReader dreader = oledbCommand.ExecuteReader(CommandBehavior.CloseConnection);
string s = "";
while (dreader.Read())
{
s += dreader["u_id"].ToString() + "\t"
+ dreader["u_name"].ToString() + "\t"
+ dreader["u_password"].ToString() + "\t"
+ dreader["u_password2"].ToString() + "\r\n";
}
textBox1.Text = s;
dreader.Close();
}
}
}
不知道怎么就错了....希望大大们能帮偶看看,给点提示...谢谢了.
下面的是我仿照连接sql2000数据库而改写的...
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Data.OleDb;
namespace lianjiemdb
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
OleDbConnection mycn = new OleDbConnection();
mycn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + AppDomain.CurrentDomain.BaseDirectory + "plzc.mdb";
OleDbCommand oledbCommand = new OleDbCommand();
oledbCommand.Connection = mycn;
oledbCommand.CommandType = CommandType.Text;
oledbCommand.CommandText = "SELECT * FROM user";
mycn.Open();
OleDbDataReader dreader = oledbCommand.ExecuteReader(CommandBehavior.CloseConnection);
string s = "";
while (dreader.Read())
{
s += dreader["u_id"].ToString() + "\t"
+ dreader["u_name"].ToString() + "\t"
+ dreader["u_password"].ToString() + "\t"
+ dreader["u_password2"].ToString() + "\r\n";
}
textBox1.Text = s;
dreader.Close();
}
}
}
不知道怎么就错了....希望大大们能帮偶看看,给点提示...谢谢了.