Visual Basic - Pregunta DataReport

Life is soft - evento anual de software empresarial
 
Vista:

Pregunta DataReport

Publicado por JL (8 intervenciones) el 01/07/2003 15:22:28
Hola y Gracias:
Por ejemplo tengo la tabla clientes. en el form tengo un textbox donde ingreso el numero de cliente, como hago para que el DataReport me muestre el reporte solo con ese registro de mi tabla, Seria la clausula Where de SQL pero como se lo envio al DataReport.
Gracias.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:Pregunta DataReport

Publicado por Roberto (21 intervenciones) el 02/07/2003 09:01:13
HOWTO: Dynamically Populate a Data Report in Visual Basic

This article was previously published under Q240019
SUMMARYThis article explains how to create a report without binding
the report to any data at design time. This allows you to generate a
report without knowing the column names within the Data Source.
MORE INFORMATIONWhen using the Data Report, textboxes must be bound
to an ADO recordset. In some situations it is necessary to generate
this data report at runtime without knowing the column names at
design time. To do this you must first have a data report included in
your project with the correct number of controls needed to display
the data being retrieved. Then open an ADO recordset and loop through
this recordset populating the controls that were placed on the data
report. The following code demonstrates how to accomplish this.

Sample Code
Start a new Visual Basic Standard EXE project. Form1 is added by
default.
From the Project menu, click References, and select the Microsoft
ActiveX Data Objects.
From the Project menu select "Add Data Report". If there is no option
for a Data Report then you will need to choose Components from the
Project and a dialog box is displayed. Click on the Designers tab and
add a reference to the Data Report.
In the Data Report properties change the Data Report name to DR.
Place two report Labels and two report Textboxes in the Detail
Section of the report.
Place a command button on Form1 named command1.
Place the following code into Form1. Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim cmd As New ADODB.Command

Private Sub Command1_Click()
Dim q As Integer%
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

RE:Pregunta DataReport

Publicado por Roberto (21 intervenciones) el 02/07/2003 09:03:49
Private Sub Command1_Click()
Dim q As Integer
Dim intCtrl As Integer
Dim x As Integer
Dim z As Integer
x = 0
q = 0
z = 0

With DR
.Hide
Set .DataSource = rs
.DataMember = ""
With .Sections("Section1").Controls
For intCtrl = 1 To .Count
If TypeOf .Item(intCtrl) Is RptLabel Then
.Item(intCtrl).Caption = rs.Fields(q).Name & " :"
q = q + 1
End If
If TypeOf .Item(intCtrl) Is RptTextBox Then
.Item(intCtrl).DataMember = ""
.Item(intCtrl).DataField = rs(z).Name
z = z + 1
End If
Next intCtrl
End With
.Refresh
.Show
End With
End Sub

Private Sub Form_Load()

Command1.Caption = "Show Report"

cn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\Program Files\Microsoft Visual
Studio\VB98\Nwind.mdb;"

With cmd
.ActiveConnection = cn
.CommandType = adCmdText
.CommandText = "Select FirstName, Lastname from Employees"
.Execute
End With

With rs
.ActiveConnection = cn
.CursorLocation = adUseClient
.Open cmd
End With

End Sub

Change the Data Source Property in the connect string to the path to
your Northwind MDB.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar