从 VisualStudio 生成的数据库内容到程序员生成的内容
我希望能够更好地访问数据库,以便我可以执行查询(主要是因为我不理解/不知道它的 API,但我知道 SQL)。 我不想删除 Visual Studio 所做的一切,因为很多内容已经建立在它的基础上,但是我如何才能获得可用于执行 SQL 查询的对象。
这是 Visual Studio 2008、C# 和 MSSQL
I'd like to be able to better access the database so I can execute queries (primarily because I don't understand/know the API for it, but I do know SQL). I don't want to remove everything Visual Studio has done because a lot is already built upon it, but how can I get an object that I can use to execute SQL queries.
This is Visual Studio 2008, C#, and MSSQL
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
尝试类似这个:
不要忘记添加:
Try something like this:
Don't forget to add:
您还可以查看 数据访问应用程序块 - 只是您在应用程序中安装的 DLL,它允许您执行 SQL 查询,并且更加简单:
You might also look into the Data Access Application Block - just a DLL you install in your app, which allows you to execute SQL queries and such much more simply:
就我个人而言,我总是会使用免费的 Ideablade DevForce:
http://www.ideablade.com/
并使用根本没有SQL!
Personally, I would always use the free Ideablade DevForce:
http://www.ideablade.com/
And use no SQL at all!
您是否想知道可以使用哪些 .NET 库对数据库执行 SQL? 如果是这样,请首先查看
SqlConnection
和SqlCommand
(如果您使用的是 SQL Server,则使用OleDbConnection
和OleDbCommand
代码>)。SqlCommand
有几个 Execute() 方法可以完成您想要的操作。ADO.NET 是一个相当庞大的野兽,但有大量的快速入门和示例代码。
Are you asking what .NET libraries you can use to execute SQL against a database? If so, start by looking at
SqlConnection
andSqlCommand
(if you're using SQL Server, otherwise useOleDbConnection
andOleDbCommand
).SqlCommand
has several Execute() methods that will do what you're looking for.ADO.NET is a pretty big beast but there are tons of quickstarts and sample code out there.
不是 100% 确定您真正要求的是什么:-),但假设您有兴趣了解如何以编程方式执行 SQL 查询,您将需要(假设 SQL Server 作为后端):
你会得到类似的结果:
当然还有一些错误处理......:-)
这有帮助吗?
Not 100% sure what you're really asking for :-), but assuming you're interested in knowing how to programatically execute a SQL query, you'll need (assuming SQL Server as the backend):
You'll have something like:
plus of course, some error handling.... :-)
Does that help that at all??
从你的问题中我不确定你在做什么,但如果你只是想学习如何使用 SqlConnection、SqlCommand 和 DataReader 对象从数据库中检索项目,请查看:
http://msdn.microsoft.com/en-us/library/haa3afyz (VS.71).aspx
I'm not sure from your question what you've got going on, but if you just want to learn how to use a SqlConnection, SqlCommand, and a DataReader object to retrieve items from a database, check this out:
http://msdn.microsoft.com/en-us/library/haa3afyz(VS.71).aspx