|
-
Aug 12th, 2010, 05:15 AM
#1
Thread Starter
New Member
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!
-
Aug 12th, 2010, 08:08 AM
#2
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
-
Aug 12th, 2010, 11:48 AM
#3
Thread Starter
New Member
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)...
-
Aug 13th, 2010, 10:48 AM
#4
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?
-
Aug 13th, 2010, 10:51 AM
#5
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
-
Aug 13th, 2010, 10:54 AM
#6
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
-
Aug 13th, 2010, 01:24 PM
#7
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.
-
Aug 13th, 2010, 01:47 PM
#8
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.
-
Aug 13th, 2010, 02:34 PM
#9
Addicted Member
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.
-
Aug 14th, 2010, 12:18 AM
#10
Thread Starter
New Member
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!!
-
Aug 14th, 2010, 12:00 PM
#11
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|