如何在asp.net中创建连接字符串? [英] How to create a connection string in asp.net?

查看:88
本文介绍了如何在asp.net中创建连接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在ASP.net中创建连接字符串?

如何在类库中创建连接字符串?我可以使用哪个类和方法以及如何调用它们?



提前致谢!

解决方案

首先,找出你的连接字符串是什么



http:// www。 connectionstrings.com/ [ ^ ]



其次,将其添加到您的应用程序配置



 <   connectionStrings  >  
< add name = SomeConnectionString connectionString = 无论 providerName = System.Data.SqlClient / >
< / connectionStrings >





三,在项目中添加对System.Configuration的引用,你可以从配置文件中读取数据



http://msdn.microsoft.com/en-us/library/ system.configuration.configurationmanager.connectionstrings.aspx [ ^ ]





string myConnectionString = ConfigurationManager.ConnectionStrings [ WhateverName]。ConnectionString;


这些是否相关?



我将假设不...



连接字符串:

1)在VS中,打开服务器资源管理器(菜单:查看...服务器资源管理器

2 )右键单击您感兴趣的数据库,然后选择属性

3)连接字符串列在属性窗口中。

4)打开Web.Config在appSettings部分下方添加:

 <   connectionStrings  >  
< 添加 名称 = MyDatabase connectionString = ...根据属性窗口连接字符串 / >
< / connectionStrings >





对象和方法:

这个是一个更大的主题。我假设您已经创建了类库,并希望使用它们中的项目。

1)如果您还没有这样做,请在您的应用程序中添加对类库的引用。

2)使用 code>如果你需要它。

3)从库中声明一个相应类类型的对象,就好像它是一个.NET内置类型。例如,如果您的类库定义了一个类MyClass,那么:

 MyClass myInstanceOfMyClass = new MyClass(); 
myInstanceOfMyClass.MYMethod();


如何在asp.net?中创建连接字符串? p $ p> 

无论是ASP.NET还是Winforms,形成连接字符串都是一样的。



在此处查看:连接字符串 [ ^ ]





在类库中如何创建对象和方法,我该如何调用它们?



创建类。对象是类的实例。方法是在类中暴露的行为。



最后,现在,根据您的最后几个问题,我建议您从那里获得一本初学者书籍并从中开始。随意做事或询问任何事都无济于事。学习,逐步移动并学习。


How can I create a connection string in ASP.net?
How can I create a connection string in a class library? Which class and methods can I use and how must I call them?

Thanks in advance!

解决方案

First, find out what your connection string will be

http://www.connectionstrings.com/[^]

Second, add it to your application configuration

<connectionStrings>
  <add name="SomeConnectionString" connectionString="Whatever" providerName="System.Data.SqlClient " />
</connectionStrings>



Third, add a reference to System.Configuration in your project and you can read the data from the config file

http://msdn.microsoft.com/en-us/library/system.configuration.configurationmanager.connectionstrings.aspx[^]


string myConnectionString = ConfigurationManager.ConnectionStrings["WhateverName"].ConnectionString;


Are these related?

I will assume not...

Connection string:
1) In VS, open the Server Explorer (Menu: "View...Server Explorer"
2) Right click the database your are interested in, and select "Properties"
3) The connection string is listed in the properties window.
4) Open your Web.Config and below the "appSettings" section add:

<connectionStrings>
  <add name="MyDatabase" connectionString="...connection string as per the properties window"/>
</connectionStrings>



Objects and methods:
This is a bigger subject. I assume you have created your class library, and want to use items from them.
1) If you haven't done so, add a reference to the class library in you app.
2) Add a using if you want it.
3) Declare an object of the appropriate class type from your library, as if it was a .NET inbuilt type. for example if your class library defines a class "MyClass" then:

MyClass myInstanceOfMyClass = new MyClass();
myInstanceOfMyClass.MYMethod();


how do i create connection string in asp.net?


Whether it be ASP.NET or Winforms, forming connection string is same in all.

Look here for it: Connection String[^]


In class library how to create object and methode,how do i call them?


Create class. Objects are instances of the class. Methods are behaviours exposed in a class.

Lastly, now, based on your last few questions, I would suggest to get a beginner book and start of from there. Doing things randomly or asking anything would not help. Study, move stepwise and learn.


这篇关于如何在asp.net中创建连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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