Results 1 to 11 of 11

Thread: Database and Data Report

  1. #1

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Posts
    6

    Database and Data Report

    Hi alll, im kinda new here but i love VB...
    anyways, here is my problem:

    I'm currently working on an Inventory System. Its kinda big IS that it took me a very long time to create. It consists of forms that has a DATAGRID components. Oh yeah, my database is a Microsoft Access 07. Well, as I was working on the IS, I took a dead on something. It was the Data Report Form. My problem is how can i display the data that's on the DATAGRID (which of course from the database) on to the Data Report Form? Can I ask if anyone know anyway to do this? It will be a great learning and help to me!

    Thanks in advance!

  2. #2
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Database and Data Report

    Use ADO and a reader. I can give you an example, but you will have to modify it for your needs.
    You will also need an ADO.NET tutorial.

    Code:
        Private Sub frmTest_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Dim strSQL As String
            'Dim cmd As SqlCommand
            Dim DA As SqlDataAdapter
            Dim DS As DataSet
            Dim DR As DataRow
    
    
            DataAccess.Initialize()
    
            mConn = New SqlConnection
            With mConn
                .ConnectionString = [String].Format(mconConnectString, DataAccess.Server, DataAccess.Database, DataAccess.User, DataAccess.Password, DataAccess.Database)
                .Open()
            End With
    
            DA = New SqlDataAdapter
            DS = New DataSet
    
            strSQL = "SELECT EmailTypeID as col1 " & _
                    " FROM tblEmailType"
            DA.SelectCommand = New SqlCommand(strSQL, mConn)
            DA.Fill(DS)
            For Each DR In DS.Tables(0).Rows
                With cboTypes.Items
                    .Add(DR(0).ToString)
                End With
            Next
    
        End Sub
    That is just to get you started. You will not be able to run it. Search for any terms you need help with.

    Ignore DataAccess.Initialize(), that is a custom object.
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  3. #3

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Posts
    6

    Re: Database and Data Report

    @Marman: what if im not using SQL... is there any other way..? but i get the part (For Next Structure)...

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Database and Data Report

    You posted your question in the VB6 and earlier section but the suggestion given by MarMan is VB.NET?

    Which language are you using?

  5. #5
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Database and Data Report

    OOOps, I keep making that mistake. One of these days I will learn to read
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  6. #6
    Frenzied Member
    Join Date
    Jan 2010
    Location
    Connecticut
    Posts
    1,687

    Re: Database and Data Report

    @bj

    You can use bound controls, I don't use them because they are too limiting but they may work for you.
    VB6 Library

    If I helped you then please help me and rate my post!
    If you solved your problem, then please mark the post resolved

  7. #7
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Database and Data Report

    If he is using VB6, and not using SQL, then the only other thing he could be using is bound controls.

  8. #8
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Database and Data Report

    To report the same data using a DataReport you would set up the same data source parameters you used for the DataGrid.

  9. #9
    Addicted Member
    Join Date
    Aug 2006
    Posts
    249

    Re: Database and Data Report

    I'm not sure if this is any help, but try this example that I have used in my clinic software that contains an inventory system, it is much easier to just pull the data straight from your database\database table. Lets say your database table is called 'inventory':


    Private Sub Command1_Click()
    On Error GoTo err:
    Dim MyCon As New ADODB.Connection
    Dim MyRs As New ADODB.Recordset
    MyRs.Open "Select * from inventory", conn, 1, 3
    With DataReport1.Sections("Section1").Controls
    .Item("Number").DataField = MyRs("Number").Name
    .Item("Product").DataField = MyRs("Product").Name
    .Item("Quantity").DataField = MyRs("Quantity").Name
    .Item("Tax1").DataField = MyRs("Tax1").Name
    .Item("Tax2").DataField = MyRs("Tax2").Name
    .Item("Total").DataField = MyRs("Total").Name
    End With
    Set DataReport1.DataSource = MyRs
    DataReport1.Show
    Exit Sub
    err:
    MsgBox "ERROR: Please check if you have set a default printer or your printer is connected properly!"
    End Sub
    Last edited by anthony_pacitto3; Aug 13th, 2010 at 02:40 PM.

  10. #10

    Thread Starter
    New Member
    Join Date
    Aug 2010
    Posts
    6

    Re: Database and Data Report

    @Marman: its ok... dont worry about the mistake... we're only humans after all...

    @hack: ok, i'll try it first...

    @dilettante: is that same as bound??

    @anthony_pacitto3: later this evening, i'll try yours...

    @all thank you everyone, if your suggestions worked i'll be very happy!! thanks again!! now, keep posting some suggestions!!

  11. #11
    PowerPoster dilettante's Avatar
    Join Date
    Feb 2006
    Posts
    24,487

    Re: Database and Data Report

    Yes, setting the DataSource and DataField properties is data binding.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width