|
Hi there,
I want to create an Crystal Report and to do that I have to fill an DataSet, but the DataSet isn't filled....why not ???
The dataset dsValuta contains 2 tables: stam_valuta and stam_valuta_koers they are linked with an foreign key on val_code when I run this code i get no error but the dataset is empty....
what can go wrong ??
[code] Dim GetDataStam_valuta As New SqlClient.SqlCommand("select stam_valuta.val_code, _ val_afk,val_dec val_krs_datum,val_krs_koers,val_krs_per FROM stam_valuta left JOIN _ stam_valuta_koers ON stam_valuta.val_code = stam_valuta_koers.val_code ORDER BY _ stam_valuta.val_code", Conn)
Dim daStam_valuta As New SqlClient.SqlDataAdapter(GetDataStam_valuta) Dim dsStam_valuta As New dsValuta() Try Conn.Open() daStam_valuta.Fill(dsStam_valuta) rptStam_valuta.SetDataSource(dsStam_valuta) CrystalReportViewer1.ReportSource = rptStam_valuta Catch ex As SqlClient.SqlException MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally Conn.Close() End Try [/code] | | MigrationUser 1 Friday, January 21, 2005 8:09 AM | Have you verified that the SQL statement returns records? | | MigrationUser 1 Friday, January 21, 2005 11:15 AM | yes the SQL statement give records back in the query analyzer but not though the dataset... what can go wrong here ??? | | MigrationUser 1 Monday, January 24, 2005 7:41 AM | You are creating a new copy of your dataset in this routine:
Dim dsStam_valuta As New dsValuta()
When this routine finishes, dsStam_valuta is destroyed and no longer exists. Either declare dsStam_valuta at the class level or forget it all together and load dsValuta directly in your Fill statement. | | MigrationUser 1 Monday, January 24, 2005 12:49 PM | I made dsValuta as an "XSD" file and therefor it is an type and cann't be used as an expression...
but what do you mean with declare at the class level ???
| | MigrationUser 1 Tuesday, January 25, 2005 8:54 AM | By "declare at the class level", I am referring to the scope of the variable. Where you declare a variable in code determines its scope (what code can access it) and its lifespan (when it no longer exists).
The code snippet you posted makes it appear that dsStam_Valuta is declared at the procedure level, that is, within a subroutine or function. Once a subroutine or function is finished, any variables created within that routine are destroyed and no longer exist (in general).
If you declare the variable at the class level, that is, outside of a any subroutine or function, but within the class you are coding, it will exist as long as an instance of the class exists.
When you are coding in a Windows Form, the form is your class. So a windows forms class, with only a subroutine to handle Form.Load, looks (more or less) like:
Public Class Form1 Inherits System.Windows.Forms.Form
[...Windows Form Designer generated code...]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
If we declare dsValuta at the procedure level, it would look like:
Public Class Form1 Inherits System.Windows.Forms.Form
[...Windows Form Designer generated code...]
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim dsStam_Valuta as New dsValuta
End Sub
End Class
Now dsStam_Valuta only exists while Form1_Load is executing. We could load it with info and read that info within this procedure. But once Form1_Load is finished dsStam_Valuta (which is a NEW copy of dsValuta) will be destroyed and will no longer exist.
But, if we declare dsStam_Valuta at the procedure level, as follows:
Public Class Form1 Inherits System.Windows.Forms.Form
[...Windows Form Designer generated code...]
Dim dsStam_Valuta as New dsValuta
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
End Sub
End Class
dsStam_Valuta will continue to exist after Form1_Load has finished. As long as Form1 exists (is open) dsStam_Valuta will exist.
Hope that helps! | | MigrationUser 1 Tuesday, January 25, 2005 10:47 AM | I tried it but without any result....
I've tested something: [code] Dim GetDataStam_valuta As New SqlClient.SqlCommand("select stam_valuta.val_code, _ val_afk,val_dec val_krs_datum,val_krs_koers,val_krs_per FROM stam_valuta left JOIN _ stam_valuta_koers ON stam_valuta.val_code = stam_valuta_koers.val_code ORDER BY _ stam_valuta.val_code", Conn)
Dim daStam_valuta As New SqlClient.SqlDataAdapter(GetDataStam_valuta) Dim dsStam_valuta As New dsValuta() Dim dt As New DataTable()
Try Conn.Open() daStam_valuta.Fill(dsStam_valuta) daStam_valuta.Fill(dt) MessageBox.Show(dsStam_valuta.stam_valuta.Rows.Count.ToString & " / " & _ dt.Rows.Count) rptStam_valuta.SetDataSource(dsStam_valuta) CrystalReportViewer1.ReportSource = rptStam_valuta Catch ex As SqlClient.SqlException MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error) Finally Conn.Close() End Try [/code]
The result is that dsStam_valuta count 0 rows and dt counts 7 rows (there ara 7 rows in the database) so why is the datatable filled and the dataset not..... | | MigrationUser 1 Wednesday, January 26, 2005 3:13 AM | I don't know what you meant by "...I made dsValuta as an "XSD" file and therefor it is an type and cann't be used as an expression..." but that must be where your problem is. You cannot "make a dataset as an XSD file"... You can design a dataset and write its schema to and XSD and its data to an XML. You can read an XSD file into a dataset to define it and read XML to fill its values. So I don't know what you've done...
There's got to be something wrong with dsValuta... If the same Fill method loads values into a standard DataTable but not into your "dataset" then something is wrong with the dataset. What is dsValuta() and why don't you just use a New DataSet? You can always write out the schema and data of the standard dataset if you need the XML files for something else... | | MigrationUser 1 Wednesday, January 26, 2005 12:04 PM |
|