t__ 0 Newbie Poster

Hi,
i'm actually trying to display records from 3 tables in a Data Report using an InputBox. That is whatever information i enter in the inputbox the data report should display its appropriate records from the tables.

i can display records from 3 tables in the data report, but how to do this using an input box?

can u just help me on this.

Thank you.

Dani AI

Generated

Hi , you can do this by (1) asking the user for the search text with InputBox, (2) using that value to build a safe query that joins your three tables, (3) executing the query into a result set (Recordset / DataTable), and (4) binding that result set to the Data Report and showing/refreshing it. Important: validate the InputBox value and use parameterized queries (or proper escaping) so you do not open yourself to SQL injection or type errors.

A common pattern in VB.NET (WinForms + ReportViewer) looks like this:

Dim search As String = InputBox("Search")
If search = "" Then Exit Sub

Dim sql As String = "SELECT t1.*,t2.*,t3.* FROM t1 INNER JOIN t2 ON ... INNER JOIN t3 ON ... WHERE t1.Name LIKE @p"
Using cn As New SqlConnection(connString)
  Using cmd As New SqlCommand(sql, cn)
    cmd.Parameters.AddWithValue("@p", "%" & search & "%")
    Dim da As New SqlDataAdapter(cmd)
    Dim dt As New DataTable()
    da.Fill(dt)
    ReportViewer1.LocalReport.DataSources.Clear()
    ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("MyDataSet", dt))
    ReportViewer1.RefreshReport()
  End Using
End Using

If you are on VB6 with the DataReport/DataEnvironment, either set a Command's SQL/parameter in the DataEnvironment before calling DataReport.Show, or fill an ADODB.Recordset from your joined SQL and bind that recordset to the report. Common gotchas: mismatched dataset schema vs. report fields, string vs. date quoting (Access vs. SQL Server), and not clearing previous report data sources before rebinding.

Post which Visual Basic version and the report control you use, plus the table relations or sample SQL, and we can give a tailored snippet.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.