C#中怎样给WinForm应用程序添加webconfig配置文件来连接数据库 C#中怎样给WinForm应用程序添加webconfig配置文件来连接数据库意思就是在项目中添加一个webconfig配置文件,里面有连接数据库的语句。及在项目中怎么用。谢谢大家 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以试试,添加app.config文件,即添加应用程序配置文件 <connectionStrings> <add name="connStr" connectionString="server=;database=;uid=sa;pwd="/> </connectionStrings> winform中添加webconfig? 添加这个appconfig 可以试试,添加app.config文件,即添加应用程序配置文件 是 app.config 配置和web大同小异 app.config文件:<?xml version="1.0" encoding="utf-8" ?><configuration> <configSections> </configSections> <connectionStrings> <add name="【自定义连接名】" connectionString="【SQL连接数据库字符串】" providerName="System.Data.SqlClient" /> </connectionStrings></configuration>调用。//从app.config读取连接字符串。 String connStr = ConfigurationManager.ConnectionStrings["【自定义连接名】"].ConnectionString; 然后接下去是 using (SqlConnection conn = new SqlConnection(connStr)) { conn.Open(); using (SqlCommand cmd = conn.CreateCommand()) {//数据库操作。//如:cmd.CommandText = "select * FROM Users where UserName='" + txtName.Text+ "'";//int i = Convert.ToInt32(cmd.ExecuteScalar());}} winform程序是用的app.config配置文件。 AxShockwaveFlash与Flash10i.ocx、InstallShield的三角恋 C# 链表删除元素时如何释放空间 有没有什么集合像SortedList可以排序,但Key可以重复 axWindowsMediaPlayer1控件屏蔽双击????急。。。。。 API问题 高手请进 Button有没有按下的效果 Datalist怎么连接网页? 写了个windows service,去启动一个软件,但是软件界面显示不出来 C#打开MDB数据问题求救 如何修改XML结点名字! 【求算法】遍历多个连续字符串 关于委托的一个小问题哈。。。
<connectionStrings>
<add name="connStr" connectionString="server=;database=;uid=sa;pwd="/>
</connectionStrings>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
</configSections>
<connectionStrings>
<add name="【自定义连接名】"
connectionString="【SQL连接数据库字符串】"
providerName="System.Data.SqlClient" />
</connectionStrings>
</configuration>调用。
//从app.config读取连接字符串。
String connStr = ConfigurationManager.ConnectionStrings["【自定义连接名】"].ConnectionString;
{
conn.Open();
using (SqlCommand cmd = conn.CreateCommand())
{
//数据库操作。
//如:cmd.CommandText = "select * FROM Users where UserName='" + txtName.Text+ "'";
//int i = Convert.ToInt32(cmd.ExecuteScalar());
}
}