运行时带有变量的报告 [英] Reports with variables in run time

查看:80
本文介绍了运行时带有变量的报告的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

晚安
我叫莫塔兹博士
我是药剂师
我是vs2008编

我有一个项目,该项目每个月都会打开一个新数据库,每天都会打开一个新表,因此我想添加一份报告,无论我如何给他提供月份名称&;要给我打印数据的日期名称.

谢谢

Good Night
my name is Dr Motaz
I am a pharmacest
and I am a vs2008 prog

I have a project and the project opens a new database every month and a new tabel every day so I want to add a report any how I give him the month name & the day name to give me the data to print.

Thanks

推荐答案

您需要做的是从用户那里获取输入的内容,并将其处理到给定的查询中以返回数据.

现在,您的操作方式将取决于日期的存储方式,例如数据库名称,表名称,列名称等.

您要做的第一件事是操纵连接字符串以访问相关的数据库.

因此,如果您的数据库名为dbMMYYYY,并且用户输入2010年7月作为输入,则连接字符串migh最终为;
数据源= myServerAddress;初始目录= db072010 ;用户ID = myUsername;密码= myPassword;"

接下来需要处理的是再次基于用户输入的数据查询,因此您可能只想返回2010年7月28日的数据,因此该字符串可能最终像;
tbl28 选择*"

然后,您可以将所有这些绑定回所需的任何控件等,和/或报告.

因此,最重要的是操纵连接字符串和sql查询的文本,完成工作. :)
What you will need to do is take the provided input from the user, and manipulate that into the given query to return the data.

Now, how you manipulate will depend on how your date is stored, e.g. database names, table names, column names etc.

First thing you will have to do is manipulate the connection string to access the relevant database.

So if your database are named dbMMYYYY and the user enters July 2010 as the input, the connections string, migh end up as;
"Data Source=myServerAddress;Initial Catalog=db072010;User Id=myUsername;Password=myPassword;"

The next thing you would need to manipulate is the data query based again on the user input, So you might want to return only the data for the 28th July 2010, so the string might end up like;
"Select * from tbl28"

You would then bind all this back to whatever controls etc. you want, and/or reports.

So, bottom line is manipulate the text of the connections string and the sql query, job done. :)


在下面的代码示例中,我有2个组合框,第一个具有从1月到12月在ide中预加载的值,第二个具有在运行时1到31中加载的值,以及一个按钮.

当您从组合中选择月份和日期"并单击按钮时,基础连接字符串和查询将根据您在我的通用解决方案的注释中提供的信息进行更新;

In the code example below, i have 2 combo box, 1st has the values preloaded in the ide for January through December, the second one has the values loaded at runtime 1 through 31, and a button.

When you select the the Month and Day from the combos and click the button, the base connection string and query will be updated based on the the info you provided in the comment to my generic solution;

Public Class Form1

Dim baseQueryConString As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\mydata\db{0}.accdb;Persist Security Info=False;"
Dim baseQueryString As String = "Select * from tab{0}"

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Load the values to the combobox date value
        For i As Integer = 1 To 31
            ComboBox2.Items.Add(i.ToString)
        Next
    End Sub


Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'output the strings
        Debug.WriteLine("Con String: " + String.Format(baseQueryConString, (ComboBox1.SelectedIndex + 1).ToString))
        Debug.WriteLine("SQL String: " + String.Format(baseQueryString, (ComboBox2.SelectedIndex + 1).ToString))

End Sub


这篇关于运行时带有变量的报告的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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