c# 连接SQL数据库,不支持关键字: “provider”。
using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
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.Configuration;
using System.Data.OleDb;
using System.Data.SqlClient;
//string ConnString = "Provider=SQLOLEDB.1;Initial Catalog=infor;Data Source=localhost;User ID=sa; Password=123";
SqlConnection con=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["sqldb"]);
con.Open();
SqlDataAdapter ada=new SqlDataAdapter("select * from kild",con);
DataSet set1=new DataSet();
ada.Fill(set1);
DataGrid1.DataSource=set1.Tables[0].DefaultView;
DataGrid1.DataBind();
运行时,出错提示“不支持关键字: “provider”。
行: 48
行 46: //string ConnString = "Provider=SQLOLEDB.1;Initial Catalog=infor;Data Source=localhost;User ID=sa; Password=123";
行 47:
行 48: SqlConnection con=new SqlConnection(System.Configuration.ConfigurationSettings.AppSettings["sqldb"]);
行 49: con.Open();
行 50: SqlDataAdapter ada=new SqlDataAdapter("select * from kild",con);
不知错在哪里,应该怎样改?
------解决方案--------------------
那就去掉 Provider=SQLOLEDB.1;
------解决方案--------------------
C# code
SqlConnection con=new SqlConnection("Initial Catalog=infor;Data Source=localhost;User ID=sa; Password=123";");