简体   繁体   English

如何使用vb.net更新特定日期的gridview的特定列值?

[英]How to update the particular column values of gridview on specific dates using vb.net?

I have column in database 我在数据库中有专栏

ID    From        To             s1from          s2to           s2price         fare

1     Delhi       Manali         17-Dec-2010     19-Dec-2010    $900            $600  
2     USA         Canada         18-Dec-2010     20-Dec-2010    $500            $800
3     Newyork     salinas        19-Dec-2010     22-Dec-2010    $760            $1000

I want when any user search For: Delhi to Manali on between 17-Dec-2010 to 19-Dec-2010 then the price would be automatically changes to $900 in gridview else the default price wold be displayed in fare is $600 if he search for DelHi to Manali after 19-Dec-2010. 我想当任何用户在2010年12月17日至2010年12月19日之间搜索:德里到马那利时,价格将自动在gridview中更改为$ 900,否则如果他搜索的话,票价中显示的默认价格为$ 600在2010年12月19日之后将DelHi带到马那利。

I m confused how to implement this logic ... using vb.net ... 我很困惑如何使用vb.net实现此逻辑...

If I understand correctly, I think you could do using this query: 如果我理解正确,我认为您可以使用以下查询:

SELECT DateSpecificFare = CASE WHEN s1from <= inDate AND s2to >= inDate THEN s2price ELSE fare END FROM YourTable WHERE From = inFrom AND To = inTo

Where inDate , inFrom and inTo would be the parameters the user selects. 其中inDateinFrominTo是用户选择的参数。

Your previous query also made it look like you might not know how to make the calls to the database so if that's the case, look at SqlCommand.ExecuteScalar which includes some sample code showing you how to do that. 您先前的查询还使您看起来好像不知道如何对数据库进行调用,因此,请查看SqlCommand.ExecuteScalar ,其中包括一些示例代码,向您展示了如何执行此操作。 Or if you need to return more than one column and/or record from your table, look at SqlCommand.ExecuteReader instead. 或者,如果您需要从表中返回多个列和/或记录,请查看SqlCommand.ExecuteReader

Btw, you should really edit your previous question rather than create a new one, otherwise it might get closed as a duplicate. 顺便说一句,您应该真正编辑上一个问题而不是创建一个新问题,否则它可能会重复出现。 But in this case I'll answer this one rather than the previous ones since this is the one with the best question. 但是在这种情况下,我将回答这个问题,而不是前面的问题,因为这是问题最严重的一个。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM