.net Windows应用程序 [英] .net windows application

查看:51
本文介绍了.net Windows应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在C#中的Windows应用程序中工作.我希望使用hpw的简单演示项目,使用app.config文件将Windows应用程序连接到sql server 2005..

im working in windows application in C#..i want a simple demo project of hpw to connect the windows application to sql server 2005 using app.config file..

推荐答案

我用它搜索了一下,并获得了1840万个结果.

[
I googled it and got back 18.4 MILLION results.

Results for ".net connect to sql server"[^]

Google reveals all.


如果您需要有关在app.config中存储连接字符串的帮助,请参见^ ]
If you need help on storing connection strings in app.config, see here[^].


在VS中,查看解决方案资源管理器.
在您的项目下,打开属性"分支.
双击"Settings.settings"
添加名为"ConnectionString"的用户字符串
关闭并保存设置.

在您的代码中:
In VS, look at the Solution Explorer.
Under your poject, open the "Properties" branch.
Double click "Settings.settings"
Add a user string called "ConnectionString"
Close and save the settings.

In your code:
string conStr = Properties.Settings.Default.ConnectionString;
using (SqlConnection con = new SqlConnection(strCon))
   {
   using (SqlCommand com = new SqlCommand("SELECT * from MyTable", con))
      {
      SqlDataReader r = com.ExecuteQuery();
      while (r.Read())
         {
         ....
         }
      }
   }


当您更改它并要保存时:


When you change it, and want to save:

Properties.Settings.Default.ConnectionString = conStr;
Properties.Settings.Default..Save();


这篇关于.net Windows应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆