在C#中,哪个文件称为vb.net模块文件 [英] In C# which file is known as vb.net module file

查看:70
本文介绍了在C#中,哪个文件称为vb.net模块文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C#中,该文件的行为类似于Vb.net模块文件.例如,我们可以在项目中任何地方的模块文件中使用函数.就像在C#中一样,我们可以使用类似的模块文件.

我在ASP.net,C#中执行Project.我想给所有文件通用的连接字符串.
所以我将在其中给出连接字符串.

有人帮忙

在此先感谢''

In C# which file is act like Vb.net Module file. For example we can use function in module file anywhere in project. That''s like in C# we can use like module file.

I am doing Project in ASP.net,C#. I want to give connection string common to all files.
so where i will give the connection string.

Anybody help please

Thanks in advance''

推荐答案


您可以在Web.config中添加连接字符串,以便可以在应用程序中的所有文件中访问.....

请参阅以下链接........

ASP.NET 2.0中Web.config内部的连接字符串加密 [
Hi,
you can Add your Connection String in Web.config So that is Accessible in All The Files In Application.....

Refer Following Link........

Encryption of Connection Strings Inside the Web.config in ASP.NET 2.0 [^]


使连接字符串通用到所有页面,则必须在
To give connection string common to all pages then you have to give in webconfig file under
<configuration>

标记下提供webconfig文件

例如:

tag

eg:

<connectionStrings>
   <add name="MenuStructureDB" connectionString="Data Source=PRASHANTH\SQLEXPRESS;Initial Catalog= MenuStructure;Integrated Security=True;" />
 </connectionStrings>



然后在后面的代码中可以调用

例如:



then in code behind you can call

eg:

SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["MenuStructureDB"].ToString());


没有一个-C#没有全局变量或方法的概念(故意遗漏,C和C ++确实有).
做到这一点的最佳方法是在单独的实用程序DLL中创建此类方法-只需将对DLL的引用添加到项目中,就可以将它们添加到多个项目中.无需为新项目更改(或什至可用)代码,从而改善了维护并可以提高可靠性.
在DLL中,创建一个静态类,然后向其添加公共静态方法.
There isn''t one - C# has no concept of global variables or methods (a deliberate omission, C and C++ did).

The best way to do this is to create such methods in a separate Utilities DLL - that way they can be added to more than one project just by adding a reference to the DLL to the project. The code does not need to be changed (or even available) to the new project, which improves maintenance, and can promote reliablity.
In the DLL, create a static class, and add public static methods to it.


这篇关于在C#中,哪个文件称为vb.net模块文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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