简体   繁体   English

通过Web服务连接到数据库

[英]Connecting to a database through a webservice

Could someone please help me to connect to a database through a webservice in c#. 有人可以帮我通过c#中的Web服务连接到数据库。

I currently have, 我目前有

  1. The webconfig with the connection string listed. 列出连接字符串的webconfig。
  2. A dbml file, which is referencing 1 table in the database I wish to query. dbml文件,该文件引用我要查询的数据库中的1个表。
  3. The asmx file with all my methods. 我所有方法的asmx文件。 These are all currently functioning, but I now wish to add some additional web methods to query the database. 这些目前都在起作用,但是我现在希望添加一些其他的Web方法来查询数据库。

Could someone please help me out. 有人可以帮我吗。

Thanks 谢谢

Since you mention you have a DBML file, I'm assuming your'e using Linq-to-SQL. 既然您提到您有一个DBML文件,所以我假设您使用的是Linq-to-SQL。 ScottGu has some great starter tutorials on using the technology. ScottGu有一些使用该技术的出色入门教程。 Here is one of them: 这是其中之一:

http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx http://weblogs.asp.net/scottgu/archive/2007/05/19/using-linq-to-sql-part-1.aspx

Bottom line at the very basic level you're DBML has a bunch of code behind including the DataContext classes that you run your queries against, using something like: 最基本的说来,您是DBML,其背后有一堆代码,其中包括运行查询所依据的DataContext类,使用的方法如下:

DataClasses1DataContext dc = new DataClasses1Datacontext();

var q = from table in dc.SomeTable
select table;

Again the link above has some really good examples of how to use Linq-to-SQL. 同样,上面的链接提供了一些非常好的使用Linq-to-SQL的示例。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM