ASP.NET 3.5 in C# 2008 From Novice to Professional Second Edition(ASP.NET 3.5(C#2008)入门 )翻译-第十章(6)

来源:互联网 发布:投票刷票软件 编辑:程序博客网 时间:2024/06/05 12:47


Running Queries in Visual StudioIf

you’ve never used SQL before, you may want to play around with it and create some sample queries before you start using it in an ASP.NET site. Most database products provide some sort of tool for testing queries. If you’re using a full version of SQL Server, you can try SQL Server Management Studio or SQL Query Analyzer. If you don’t want to use an extra tool, you can run your queries using the Server Explorer window described earlier. Just follow these steps in Visual Studio:

在Visual Studio中运行查询

如果您之前从未使用过SQL,想要ASP.NET网站中创造一些样本查询,然后再开始使用它,您可能无从下手。大多数的数据库产品提供某种测试查询的工具。如果您使用的是完整版本的SQL Server ,您可以尝试用SQL Server Management Studio或SQL查询分析器。如果你不想使用额外的工具,您可以使用前面描述的服务器资源管理器窗口运行您的查询。在Visual Studio中只要按照这些步骤:

1. Right-click your connection, and choose New Query.

2. Choose the table (or tables) you want to use in your query from the Add Table dialog box (as shown in Figure 15-5), click Add, and then click Close.

3. You’ll now see a handy query-building window. You can create your query by adding check marks next to the fields you want, or you can edit the SQL by hand in the lower portion of the window. Best of all, if you edit the SQL directly, you can type in anything—you don’t need to stick to the tables you selected in step 2, and you don’t need to restrict yourself to Select statements.

4. When you’re ready to run the query, select Query Designer->Execute SQL from the menu. Assuming your query doesn’t have any errors, you’ll get one of two results. If you’re selecting records, the results will appear at the bottom of the window (see Figure 15-6). If you’re deleting or updating records, a message box will appear informing you how many records were affected.

1 、右键单击您的连接,并选择新建查询。     

2 、从添加表对话框中选择在您的查询中要使用的表(或多个表),(如在图15-5 ),单击添加,然后单击关闭。

3 、现在您可以看到一个方便的查询建设的窗口。您可以点击旁边的复选标志,增加你想要的字段创建您的查询,或者你可以在底部的窗口手动修改SQL语句。最重要的是,如果您直接修改SQL语句,您可以输入任何语句,你不需要坚持您在步骤2选择的表格,你不需要把自己限制Select语句中。     

4 、当您准备运行查询,选择查询设计->执行SQL的菜单。假设你的查询没有任何错误,你会得到两个结果。如果您选择记录,结果将显示在窗口底部的(见图15-6 )。如果您删除或更新记录,会出现一个消息框通知你有多少记录受到影响。

原创粉丝点击