如何VS2008 创建ODBC数据库

如何VS2008 创建ODBC数据库,第1张

public static DataBase CreateData(string DataNameInConfigfile)

{string pn = ConfigurationManager.ConnectionStrings[DataNameInConfigfile].ProviderName//读取配置文件

string cs = ConfigurationManager.ConnectionStrings[DataNameInConfigfile].ConnectionString

//下面判断数据库类型并创建相应的对象

if (pn.ToUpper().Contains("OLEDB"))

{OleDbDataAdapter oledbda = new OleDbDataAdapter()

oledbda.SelectCommand = new OleDbCommand()

oledbda.SelectCommand.Connection = new OleDbConnection(cs)

return new DataBase(oledbda)}

if (pn.ToUpper().Contains("SQL"))

{SqlDataAdapter sqlda = new SqlDataAdapter()

sqlda.SelectCommand = new SqlCommand()

sqlda.SelectCommand.Connection = new SqlConnection(cs)

return new DataBase(sqlda)}

if (pn.ToUpper().Contains("ODBC"))

{OdbcDataAdapter odbcda = new OdbcDataAdapter()

odbcda.SelectCommand = new OdbcCommand()

odbcda.SelectCommand.Connection = new OdbcConnection(cs)

return new DataBase(odbcda)}

return null}

public static DataBase CreateData(string ConnectionString, string ProviderName)

{//以下判断数据库类型并创建相应的对象

if (ProviderName.ToUpper().Contains("OLEDB"))

{OleDbDataAdapter oledbda = new OleDbDataAdapter()

oledbda.SelectCommand = new OleDbCommand()

oledbda.SelectCommand.Connection = new OleDbConnection(ConnectionString)

return new DataBase(oledbda)}

if (ProviderName.ToUpper().Contains("SQL"))

{SqlDataAdapter sqlda = new SqlDataAdapter()

sqlda.SelectCommand = new SqlCommand()

sqlda.SelectCommand.Connection = new SqlConnection(ConnectionString)

return new DataBase(sqlda)

}if (ProviderName.ToUpper().Contains("ODBC"))

{OdbcDataAdapter odbcda = new OdbcDataAdapter()

odbcda.SelectCommand = new OdbcCommand()

odbcda.SelectCommand.Connection = new OdbcConnection(ConnectionString)

return new DataBase(odbcda)

}return null}}

答案补充

connectionStrings

add name="myData" connectionString="Provider=Microsoft.Jet.OLEDB.4.0Data Source=|DataDirectory|\WebData.aspx" providerName="oledb"/

配置文件,上边你自己改下,因为系统只能输入500个字符只能那样发给你了

add name="mySql" connectionString="Data Source=administrator\SQL2005Initial Catalog=GustBookPersist Security Info=TrueUser ID=saPassword=584077432" providerName="System.Data.SqlClient"/

/connectionStrings

没有问题啊System.Configuration.ConfigurationManager.appSettings["constring"].ToString()这个可以得到value的值啊

也许是你的value连接字符串除了问题啦

value="server=服务器地址uid=数据库用户名pwd=密码database=数据库名"


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/tougao/11658962.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-17
下一篇 2023-05-17

发表评论

登录后才能评论

评论列表(0条)

保存