如何从C#代码运行dtq文件中的SQL查询 [英] How to run sql query which is in dtq file from C# code

查看:72
本文介绍了如何从C#代码运行dtq文件中的SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,

在我的项目中,我正在处理Microsoft SQL Server数据库.
我知道从我的C#代码中检索数据的一种方法:

Dear all,

in my project I''m dealing with Microsoft SQL Server database.
I know one way of retrieving data from it from my c# code:

SqlCommand myCommand = new SqlCommand("select something from someTable where someCondition", myConnection);
     SqlDataReader myReader = myCommand.ExecuteReader();



并且数据现在位于myReader对象中.很好.

但是,无论如何,通过创建数据库查询并将其保存在* .dtq文件中,对我而言,查询要容易得多.
所以我的问题是,是否可以以与上述类似的方式从C#代码中调用* .dtq文件中的查询,如果可以的话,该怎么做.

在此先感谢.



and data is now in myReader object. That''s fine.

But making query is much easier, for me anyway, by creating Database Query and saving it in *.dtq file.
So my question would be, whether it''s possible to call query which is in *.dtq file from C# code in a similar fashion as above, and if it is, how to do it.

Thanks in advance.

推荐答案

常用的方法是通过SQL Server数据库中的存储过程.然后,您可以调用存储过程并将任何必需的参数传递给它.

至于您的原始问题,不,我认为使用dtq文件不是一种非常流行的方法. :〜
A common way of doing this is via stored procedures in the SQL server database. You can then invoke the stored procedures and pass it any required arguments.

And as for your original question, no, I don''t think using dtq files is a very popular approach. :~


好的,谢谢.我现在看到自己的方式有误.

在Nishant Sivakumar建议使用存储过程作为该问题的解决方案之后,我在Internet上进行了一些阅读,因此,如果您遇到的问题与我相同(一次),并且您习惯使用C#和/或VB,但只知道有所不同数据库和SQL的基础知识,以下是我认为对您有用的内容:

http://databases.about.com/od/sqlserver/a/storedprocedure.htm [ ^ ]
要了解什么是存储过程,为什么要使用存储过程,而不是查询,比

http://www.sql-server-performance.com/articles/dba/stored_procedures_basics_p1.aspx [^ ]
详细讨论该主题,并最终确定

http://www.csharpfriends.com/articles/getarticle.aspx?articleid=78 [ ^ ]
了解如何从C#代码调用存储过程.

再次感谢您的帮助.
Ok, thanks. I see error of my ways now.

After Nishant Sivakumar suggested stored procedures as solution for the problem, I did some reading on the internet, so if you have the same problem as I did (once upon the time) and you are used to C# and/or VB but know only vary basics of databases and SQL, here is what I think to be usefull for you to read:

http://databases.about.com/od/sqlserver/a/storedprocedure.htm[^]
to get the basic idea what is stored procedure and why to use it, and not query, than

http://www.sql-server-performance.com/articles/dba/stored_procedures_basics_p1.aspx[^]
to cover the topic in more detail, and finaly

http://www.csharpfriends.com/articles/getarticle.aspx?articleid=78[^]
to learn how to call your stored procedures from C# code.

Thanks again for help.


这篇关于如何从C#代码运行dtq文件中的SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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