asp.net - mysql if else 用于 asp.net gridview

标签 asp.net mysql gridview

我正在尝试找出一种方法来做到这一点:

If (blah = 0 then 'Yes' else if blah = 1 then 'no' else 'maybe')

在mysql.我正在尝试这样做,因为我通过以下方式将所有数据插入到 gridview 中:

    Dim strSQL As String
    strSQL = "SELECT id, billing_first_name, billing_last_name, billing_email, billing_address, billing_city, billing_state, billing_zip, " & _
                "total, price_mode, process_status, 1 as num_of_items " & _
             "FROM orders " & _
             "ORDER BY created_on DESC, processed_on DESC LIMIT 0, 20;"

    Dim dtReader As MySqlDataReader
    objCmd = New MySqlCommand(strSQL, objConn)
    dtReader = objCmd.ExecuteReader()

    grdView.DataSource = dtReader
    grdView.DataBind()

如果我可以在上面的 vb.net 代码中而不是在数据库中执行 if/then/else 操作,那就太好了。我更习惯用普通的查询代码这样做。

我目前只能使用 if 和 then else 来完成此操作,而不是 if、elseif 和 then else。

SELECT IF(process_status = 1, 'SUCCEEDED', 'blah') as message, id,...

谢谢!

最佳答案

在 SQL 中,这样做是这样的:

select 
      case blah when 1 then 'yes' 
                when 0 then 'no' 
      else 'maybe' end as blah ,
      columnb  ,
      columnc
from table

关于asp.net - mysql if else 用于 asp.net gridview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11940816/

相关文章:

asp.net - ConfigurationManager.GetSection 返回 null 显然正确 'path'

asp.net - SQL Server SSRS 2012 网页中的 HTTP 元标记

php - DATE php 和 mysql 唯一

c# - 如何在 GridView 行悬停上显示工具提示

asp.net - 从 Gridview 检索绑定(bind)数据

vb.net - Devexpress Gridview editform如何在中间打开?

c# - ASP .NET C# SQL 在 ExecuteScalar 上返回 DBNULL

javascript - 如何在鼠标悬停按钮时显示或隐藏面板

php - 从第一个表中选择所有内容,计算第二个表中 ID 的实例数

MYSQL 选择另一个表中出现的多个 id 的计数