mysql - 为 Crystal Reports SQL 命令变量赋值

标签 mysql vb.net crystal-reports

我在 Crystal Report Database Expert 上放置了一个 SQLCommand,以便我可以根据 SQL 查询的结果创建自定义报告。

Here is the Sample SQL Code:
"SELECT Inventory.ItemID, Inventory.Item, 
 SUM(CASE WHEN DATE(Inventory.ItemTransactionDate) < @DateSelected THEN Inventory.Quantity ELSE 0 END) - 
 SUM(CASE WHEN DATE(consumeditemmonitoring.TransactionDate) < @DateSelected THEN consumeditemmonitoring.Quantity ELSE 0 end) - 
 SUM(CASE WHEN DATE(damagedinventory.ItemTransactionDate)< @DateSelected THEN damagedinventory.Quantity ELSE 0 end) AS 'PrevBalance',

 SUM(CASE WHEN DATE(Inventory.ItemTransactionDate) = @DateSelected THEN Inventory.Quantity else 0 END) AS 'DeliveredToday',

 SUM(CASE WHEN DATE(damagedinventory.ItemTransactionDate) = @DateSelected THEN damagedinventory.Quantity ELSE 0 END) AS 'DamagedToday',

 SUM(CASE WHEN DATE(consumeditemmonitoring.TransactionDate) = @DateSelected THEN consumeditemmonitoring.Quantity ELSE 0 END) AS 'ConsumedToday',

 SUM(CASE WHEN DATE(Inventory.ItemTransactionDate) < @DateSelected THEN Inventory.Quantity else 0 end)-
 SUM(CASE WHEN DATE(consumeditemmonitoring.TransactionDate) < @DateSelected THEN consumeditemmonitoring.Quantity ELSE 0 END)-
 SUM(CASE WHEN DATE(damagedinventory.ItemTransactionDate) < @DateSelected THEN damagedinventory.Quantity ELSE 0 END)-
 SUM(CASE WHEN DATE(consumeditemmonitoring.TransactionDate) = @DateSelected THEN consumeditemmonitoring.Quantity ELSE 0 END)-
 SUM(CASE WHEN DATE(damagedinventory.ItemTransactionDate) = @DateSelected THEN damagedinventory.Quantity ELSE 0 END)+
 SUM(CASE WHEN DATE(Inventory.ItemTransactionDate) = @DateSelected then Inventory.Quantity ELSE 0 end) AS 'Total Balance' 

 FROM Inventory 
 LEFT OUTER JOIN consumeditemmonitoring ON consumeditemmonitoring.ID = Inventory.ID 
 LEFT OUTER JOIN damagedinventory ON damagedinventory.ID = Inventory.ID
 GROUP BY  Inventory.ItemID"

我的示例 VB.Net 代码

   If MysqlConn.State = ConnectionState.Open Then
        MysqlConn.Close()
    End If
    MysqlConn.Open()

    Dim PrintingMyDataAdapter As New MySqlDataAdapter
    Dim PrintingMyDataTable As New DataTable
    Dim PrintingDDataQuery As String

    PrintingDDataQuery ="[SQLCommand]"
    Command = New MySqlCommand(PrintingDDataQuery, MysqlConn)
    PrintingMyDataAdapter.SelectCommand = Command
    PrintingMyDataAdapter.Fill(PrintingMyDataTable)

    Dim objRpt As New CustomerOrder
    objRpt.SetDataSource(PrintingMyDataTable)

如何使用 VB.net 填充 (“@DateSelected”) SQL 变量?

最佳答案

向您的命令添加一个参数。对于 SQL 来说是这样的:

SqlParameter parameter = Command.Parameters.Add("@DateSelected",System.Data.SqlDbType.DateTime);
parameter.Value = DateTime.Now;

我确信 MySQL 会非常相似

这可能有帮助:Using DateTime in a SqlParameter for Stored Procedure, format error

关于mysql - 为 Crystal Reports SQL 命令变量赋值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57140939/

相关文章:

php - mysql/php随机

Mysql,如何保存 '😘'这样的特殊字符?

c# - 在同一解决方案中使用 VB.NET 和 C#

vb.net - 如何转换整数?到VB.NET中的整数?

.net - 将信息从引用的类传递回调用表单

visual-studio-2005 - 如何在没有紧密链接的数据库连接的情况下使用 Crystal Reports?

mysql - pentaho维度数据表无法输入mysql

mysql - 在不同的月份和总值上加入同一个表中的两个查询

c# - 如何在 Crystal 报表中动态插入图片

c# - 通过代码发送数据集时,VS2010 Crystal Reports 要求登录。