Oracle SQL查询在SQL Developer中工作,但在ASP.NET中不工作 [英] Oracle SQL Query Working in SQL Developer but not in ASP.NET

查看:53
本文介绍了Oracle SQL查询在SQL Developer中工作,但在ASP.NET中不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Oracle上有一个返回值的查询:



I have a query on Oracle that returns a value:

SELECT a.ship_date ,a.judge_flag from ship_pallet_info  a inner join ship_request_info
b on a.ship_request_no = b.ship_request_no
where a.ship_date between :date1 and :date2 and a.judge_flag= :judgement;



and same query in ASP.NET like this but does not return any value:

<pre lang="vb">code.OCon.Close()
          code.OCon.Open()
          Dim cmd As New OracleCommand(&quot;SELECT * from ship_pallet_info  a inner join ship_request_info  b on a.ship_request_no = b.ship_request_no where a.ship_date between :date1 and :date2 and a.judge_flag = :judge&quot;, code.OCon)
          cmd.Parameters.Add(New OracleParameter(&quot;date1&quot;, txtPeriod_1.Text))
          cmd.Parameters.Add(New OracleParameter(&quot;date2&quot;, txtPeriod_1.Text))
          cmd.Parameters.Add(New OracleParameter(&quot;judge&quot;, txtPeriod_1.Text))
          Dim dt As New DataTable
          Dim da As New OracleDataAdapter(cmd)
          da.Fill(dt)
          gvShippingStatus.DataSource = dt
          gvShippingStatus.DataBind()</pre>







我的代码出了什么问题?有帮助吗?谢谢!




What's wrong with my code? Any help? Thanks!

推荐答案

您使用 txtPeriod_1.Text 作为所有三个参数的值。虽然 date1 date2 可能(但可能不是),但对于判断这肯定是错误的。



可能与这里的问题无关,但将日期存储为文本是一个非常糟糕的主意。



我还建议你为你的控件使用更具表现力的名字。如果您的文本框变量的名称类似于FromDateInput,UntilDateInput和JudgeFlagInput,您可能已经发现了这一点;)
You're using txtPeriod_1.Text as the value for all three parameters. While it may be intended (but probably not) for date1 and date2, for judge it's certainly by mistake.

Possibly not related to the problem here, but storing dates as text is a really bad idea.

I also would suggest you to use more expressive names for your controls. You might have spotted this yourself if your textbox-variables had names like "FromDateInput", "UntilDateInput" and "JudgeFlagInput" ;)


这篇关于Oracle SQL查询在SQL Developer中工作,但在ASP.NET中不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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