Question Textbox Forms to Report

mac-duff

Member
Joined
Dec 21, 2009
Messages
24
Programming Experience
Beginner
Hello,

I wrote an application which reads data out of a MSSQL database and display these in Textboxes. Now I want to print it and guess the easiest way is with creating a report.

This is a part of my code to display the values:

VB.NET:
Private Sub ComboBox_NumModificacion_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox_NumModificacion.SelectedIndexChanged
        On Error Resume Next
        Dim sqlConn As New SqlConnection("server=srvmti;database=SHF;Integrated Security=True")

        sqlConn.Open()

        Dim sqlComm As New SqlCommand("SELECT IdGama,NombreGama,NumModificacion,DescModificacion,Activa,Proyecto,IdCarro,IdMaquina,Fecha,tRegAuto,ControlPotencia,PotenciaSold,RetardoInicio,TiempoSold,TiempoEnfr,TiempoSubida,PosicionInicial,CorrienteSoldadura,PresionSoldadura,PresionEnfriamiento,TempPiovan,PosicionPrensa,NumMoldes,Utillaje,Portapiezas,Plancha,Observaciones FROM Gamas where IdGama=" & ComboBox_IDGama.Text & " and NumModificacion=" & ComboBox_NumModificacion.Text, sqlConn)

        Dim r As SqlDataReader = sqlComm.ExecuteReader()
        While r.Read()
            Dim NombreGama As String = CStr(r("NombreGama"))
            TextBox_NombreGama.Text = NombreGama
            Dim NumModificacion As String = CStr(r("NumModificacion"))
            If ComboBox_NumModificacion.Items.IndexOf(NumModificacion) = True Then
                ComboBox_NumModificacion.Items.Add(NumModificacion)
            End If
            Dim DescModificacion As String = CStr(r("DescModificacion"))
            TextBox_DescModificacion.Text = DescModificacion
            Dim Activa As String = CStr(r("Activa"))
            CheckBox_Activa.CheckState = Activa
            Dim Carro As Integer = CStr(r("IdCarro"))
            If Carro = "0" Then
                ComboBox_IdCarro.Text = "Carro inferior"
            End If
            If Carro = "1" Then
                ComboBox_IdCarro.Text = "Carro superior"
            End If
            
        End While
        r.Close()
        sqlConn.Close()

    End Sub

But how can I send the textboxes to a report? I am getting crazy with that or do I do so bad?

Here is a pic how my app "looks"
70479712.jpg


Hope someone can me help out of this
 
I would suggest that instead of using a DataReader to poplulate your controls, create a Typed DataSet and fill the data from your database into it, use that to populate your controls. In crystal you can create your report based on your DataSet and when your ready to call the report you just pass it your filled DataSet.
 
Hi,

I guess you are right. I have created a DataSource and dropped all columns in but now I have this terrible menu on the top and I would like to use my controls (IDGama and NumModification), means I have to different fields for selecting and I dont know where I can change the function of this buttons...
 
Hi,

can please someone advise me how to read the data source?

I chose add new data source and have now to my right site all the fields which I can easily drop into a form.

Now my question is, how can I address a field from a code (eg. IdGama) like Select * from blablabla
A kind of code like this:
SHFDataSet.Tables.IndexOf("IDGama")

but I dont know how to do this :(
 
I got it working with that:

Dim shfds As SHFDataSet = Me.SHFDataSet
Dim Gamas As SHFDataSet.GamasDataTable = shfds.Gamas

Dim row_count As Integer = 0
For Each drDSRow In SHFDataSet.Tables("Gamas").Rows()
Dim IdGama_str As SHFDataSet.GamasRow = Gamas.Rows(row_count)

If ComboBox1.Items.IndexOf(IdGama_str.IdGama) = True Then
ComboBox1.Items.Add(IdGama_str.IdGama)
End If
row_count = row_count + 1

Next
 
another point,

how can I update the data on the server?

VB.NET:
            Dim shfds As SHFDataSet = Me.SHFDataSet
            Dim Gamas As SHFDataSet.GamasDataTable = shfds.Gamas

            Dim drDSRow As DataRow
            Dim row_count As Integer = 0
            For Each drDSRow In SHFDataSet.Tables("Gamas").Rows()

                Dim Gama_str As SHFDataSet.GamasRow = Gamas.Rows(row_count)

                If (Gama_str.IdGama) = ComboBox_IDGama.Text Then
                    Gama_str.BeginEdit()
                    Gama_str("NombreGama") = "1234567"
                    Gama_str.EndEdit()
                    Gama_str.AcceptChanges()
                End If

                row_count = row_count + 1

            Next

When I browse through my application I see the modifications until I close it, which means I have to send the changes somehow to the server, but how?
 
Back
Top