ASP页面的SQL查询 [英] SQL query from ASP page

查看:70
本文介绍了ASP页面的SQL查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是ASP的新手,我正在尝试查询MS SQL数据库(Northwind)。我想要用文本框设置页面,用户输入一个

逗号分隔数字的列表,查询类似于:


从category('''','''','''',''4'',''5'')中的categoryid类别中选择*


,我认为结果将在数据网格中。在查询

分析器中这很容易,但是把它放在网页表格上似乎很难。(对我来说)


这似乎不太可能,是有可能吗?建议?

解决方案

这是可能的。

您是否使用ASP或ASP.NET?在旧的ASP2.0中,您将需要构建HTML

datagrid作为HTML。 ASP.NET将为您完成此任务。

让我知道您使用的是哪个版本的ASP,我可以帮助您使用

一些样本。


我在Visual Web Developer 2005快递版btea 2中使用ASP.net。


代码:

< form id =" form1" runat =" server">

< div>

< asp:TextBox ID =" TextBox1" runat =" server"

TextMode =" MultiLine">< / asp:TextBox>

< asp:Button ID =" Button1" RUNAT = QUOT;服务器"文本= QUOT;按钮和QUOT; />< br />

< br />

< asp:GridView ID =" GridView1" runat =" server"

AutoGenerateColumns =" False" DataKeyNames =" CategoryID"

DataSourceID =" SqlDataSource1">

< Columns>

< asp:BoundField DataField =" ; CategoryID"

HeaderText =" CategoryID" InsertVisible =" False"

ReadOnly =" True"的SortExpression = QUOT;类别ID" />

< asp:BoundField DataField =" CategoryName"

HeaderText =" CategoryName"的SortExpression = QUOT;类别名称" />

< asp:BoundField DataField =" Description"

HeaderText =" Description"的SortExpression = QUOT;描述" />

< / Columns>

< / asp:GridView>

< asp:SqlDataSource ID =" SqlDataSource1" runat =" server"

ConnectionString ="<%


ConnectionStrings:NorthwindConnectionString%>"

SelectCommand = SELECT [CategoryID],[CategoryName],

[描述] FROM [Categories] WHERE([CategoryID] = @CategoryID)">

< SelectParameters> ;

< asp:ControlParameter ControlID =" TextBox1" Name =" CategoryID"

PropertyName =" Text"

Type =" Int32" />

< / SelectParameters>

< / asp:SqlDataSource>


< / div>

< / form>


" alex_s"写道:

这是可能的。

您是否使用ASP或ASP.NET?在旧的ASP2.0中,您必须以HTML格式构建数据网格。 ASP.NET将为您完成此任务。
让我知道您使用的是什么版本的ASP,我可以帮助您使用
一些示例。



I''m new at ASP and I''m trying to query an MS SQL database (Northwind). I
want the page to be setup with a textbox where the user inputs a list of
comma separated numbers and the query would be something like:

select * from categories where categoryid in (''1'',''2'',''3'',''4'',''5'')

and the results would be in a datagrid, I think. This is easy in Query
analyzer but putting it on a web form seems very hard.(for me)

This doesn''t seem possible, is it possible? suggestions ?

解决方案

It is possible.
Aare you using ASP or ASP.NET? In old ASP2.0 you will have to build you
datagrid as HTML. ASP.NET will do this for you.
Let me know what version of ASP are you using and I can help you with
some samples.


I''m using ASP.net in Visual Web Developer 2005 express edition btea 2.

code:
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server"
TextMode="MultiLine"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Button" /><br />
<br />
<asp:GridView ID="GridView1" runat="server"
AutoGenerateColumns="False" DataKeyNames="CategoryID"
DataSourceID="SqlDataSource1">
<Columns>
<asp:BoundField DataField="CategoryID"
HeaderText="CategoryID" InsertVisible="False"
ReadOnly="True" SortExpression="CategoryID" />
<asp:BoundField DataField="CategoryName"
HeaderText="CategoryName" SortExpression="CategoryName" />
<asp:BoundField DataField="Description"
HeaderText="Description" SortExpression="Description" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%


ConnectionStrings:NorthwindConnectionString %>"
SelectCommand="SELECT [CategoryID], [CategoryName],
[Description] FROM [Categories] WHERE ([CategoryID] = @CategoryID)">
<SelectParameters>
<asp:ControlParameter ControlID="TextBox1" Name="CategoryID"
PropertyName="Text"
Type="Int32" />
</SelectParameters>
</asp:SqlDataSource>

</div>
</form>

"alex_s" wrote:

It is possible.
Aare you using ASP or ASP.NET? In old ASP2.0 you will have to build you
datagrid as HTML. ASP.NET will do this for you.
Let me know what version of ASP are you using and I can help you with
some samples.



这篇关于ASP页面的SQL查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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