读书人

System.ArgumentException: 不支持关键

发布时间: 2012-01-12 22:11:58 作者: rapoo

System.ArgumentException: 不支持关键字: “provider”
错误信息
System.ArgumentException: 不支持关键字: “provider”

行 314:public static DataTable GetDataTable(string strSQL)
行 315:{
行 316:SqlConnection Conn = new SqlConnection(strConn);
行 317://DataTable datatable=new DataTable();
行 318:try


原码
-------------------------------------

using System;
using System.Configuration;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Data;
using System.Collections;
using System.ComponentModel;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.IO;


namespace Rose.DataClass
{public class CDataBase
{

static string dppath =HttpContext.Current.Request.PhysicalApplicationPath + "\\ " + ConfigurationSettings.AppSettings[ "Sql_Conn "];
protected static string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " +dppath+ "; ";

protected static string strSQL;
protected static SqlConnection Conn;
protected string strMessage;
protected static SqlConnection ConnDr;

public CDataBase()
{
//
// TODO: 在此处添加构造函数逻辑
//

}
public string Message
{
get
{
return strMessage;
}
set
{
strMessage = value;
}
}

public static DataTable GetDataTable(string strSQL)
{
SqlConnection Conn = new SqlConnection(strConn);
//DataTable datatable=new DataTable();
try
{
Conn.Open();
SqlDataAdapter sda = new SqlDataAdapter(strSQL,Conn);
DataTable dt = new DataTable( "dt ");
sda.Fill(dt);
return dt;
}
catch(System.Data.SqlClient.SqlException e)
{
throw new Exception(e.Message);
}
finally
{
Conn.Close();
}
}




[解决办法]
System.ArgumentException: 不支持关键字: “provider”
===================================================
不是你提供的protected static string strConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= " +dppath+ "; ";这一行

它找到的错误是小写的(大小写不关键,但你的代码那里还有小写的provider)
[解决办法]
改用 OLEDB
[解决办法]
Data Source= 'fdc.mdb ';Jet OLEDB:database password=123; Provider= 'Microsoft.Jet.OLEDB.4.0 ';User ID=Admin
连接字符串
[解决办法]
呀,LZ 你竟然要 SqlConnection 去连 Access ????

请使用 OleDbConnection 以及相关类



public static DataTable GetDataTable(string strSQL)
{
SqlConnection Conn = new SqlConnection(strConn);
//DataTable datatable=new DataTable();
try
{
Conn.Open();
SqlDataAdapter sda = new SqlDataAdapter(strSQL,Conn);
DataTable dt = new DataTable( "dt ");
sda.Fill(dt);
return dt;
}
catch(System.Data.SqlClient.SqlException e)
{
throw new Exception(e.Message);
}
finally
{
Conn.Close();
}
}


》》》
public static DataTable GetDataTable(string strSQL)
{
OleDbConnection Conn = new OleDbConnection(strConn);
//DataTable datatable=new DataTable();
try
{
Conn.Open();
OleDbDataAdapter sda = new OleDbDataAdapter(strSQL,Conn);
DataTable dt = new DataTable( "dt ");
sda.Fill(dt);
return dt;
}
catch(System.Data.OleDbClient.OleDbException e)
{
throw new Exception(e.Message);
}
finally
{
Conn.Close();
}
}


Good Luck!



[解决办法]
呵呵,才发现,楼上说的对

读书人网 >asp.net

热点推荐