如何将userinputs转换为sql查询 [英] How to get userinputs into sql query

查看:61
本文介绍了如何将userinputs转换为sql查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我正在学习之旅,现在我已经达到了将ASP网站形式的参数传递到我的SQL查询的程度。但我怎么做到这一点?

我希望有2个文本框或列表框,用户可以请求年份和月份来获得财务周转。



但是如何将它插入Query并将Query绑定到我的输入控件?



我的代码如下:



备注我当前的输入代码,名为UserInputYEAR和UserInputMonth



我尝试过: < br $>


  SELECT  CAST(SUM(客户。[销售(LCY)] ) AS   decimal  8  2 )) AS  Totalsales,Cust。[客户编号],Customer.Name,Customer。[Sell-to 类型] 
FROM [客户。分类帐输入] AS Cust INNER JOIN
客户 ON 客户。[客户编号] =客户。[编号]
WHERE (年份(客户。[发布日期])= UserInputYEAR (MONTH(客户。[发布] 日期])= UserInputMONTH
GROUP BY 客户。[客户编号],客户名称,客户。[销售给类型]
ORDER BY Totalsales DESC

解决方案

这取决于你使用什么来访问你的数据库。如果你正在使用ado.net,那么看看这个;



参数化查询ADO.Net [ ^ ]


您好
您可以查看此代码和请参阅您的代码,这将对您有所帮助



 <   asp:SqlDataSource     ID   =  SqlDataSource1    runat   =  server    ConnectionString   =  <% 

ConnectionStrings:TestConnectionString %> SelectCommand = SELECT * FROM [UserMaster] WHERE([EMPID] = @EMPID) >
< SelectParameters >
< asp :ControlParameter ControlID = TextBox1 名称 = EMPID 镨opertyName = 文字 类型 = 字符串 / >
< / SelectParameters >
< span class =code-keyword>< / asp:SqlDataSource >


Hello everyone,
I'm on a learning journey and now i have reached the point of passing parameters from an ASP websiteform into my SQL Query. But how do I get that?
I would like to have either 2 textboxes or listboxes where the user can request year and month for getting finansial turnover.

But how do I get that into the Query and bind the Query to my input controls?

My code is as follows:

Remark my current input code which is named UserInputYEAR and UserInputMonth

What I have tried:

SELECT        CAST(SUM(Cust.[Sales (LCY)]) AS decimal(8, 2)) AS Totalsales, Cust.[Customer No.], Customer.Name, Customer.[Sell-to Type]
FROM            [Cust. Ledger Entry] AS Cust INNER JOIN
                         Customer ON Cust.[Customer No.] = Customer.[No.]
WHERE        (YEAR(Cust.[Posting Date]) = UserInputYEAR and (MONTH(Cust.[Posting Date]) = UserInputMONTH
GROUP BY Cust.[Customer No.], Customer.Name, Customer.[Sell-to Type]
ORDER BY Totalsales DESC

解决方案

It depends what you use to access your database. If you're using ado.net then have a look through this;

Parameterized Queries ADO.Net[^]


Hi you can look this code and refer in your code this will help you

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


ConnectionStrings:TestConnectionString %>" SelectCommand="SELECT * FROM [UserMaster] WHERE ([EMPID] = @EMPID)"> <SelectParameters> <asp:ControlParameter ControlID="TextBox1" Name="EMPID" PropertyName="Text" Type="String" /> </SelectParameters> </asp:SqlDataSource>


这篇关于如何将userinputs转换为sql查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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