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.
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)...
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?
Re: Database and Data Report
OOOps, I keep making that mistake. One of these days I will learn to read:(
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.
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.
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.
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
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!! :wave:
Re: Database and Data Report
Yes, setting the DataSource and DataField properties is data binding.