2 回答
TA贡献1862条经验 获得超6个赞
将 using 添加
System.Data.OleDb.OleDbConnection;
到文件顶部,并删除 usingSystem.Data.SqlConnection;
将您的代码更改为。
using (OleDbConnection con = new OleDbConnection(connDB)) //这里是错误{}
TA贡献1797条经验 获得超6个赞
而不是使用SqlConnection,您应该使用OleDbConnection,因为SqlConnection试图将您的连接字符串读取为 SQL Server 连接字符串而不是 Access 数据库之一:
try
{
OleDbConnection conn = new OleDbConnection(connectionString);
if (conn.State == ConnectionState.Closed)
{
conn.Open();
}
String OleDb = "SELECT [Bank], [Amount] FROM [BankDetails]";
using (OleDbCommand cmd = new OleDbCommand(OleDb, conn))
{
using (OleDbDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
Response.Write("" + reader.GetString(0));
}
}
}
}
catch (Exception ex)
{
Response.Write(ex);
}
- 2 回答
- 0 关注
- 174 浏览
添加回答
举报