?fill dataTable created at design time with dataAdpter at runtime

G

Guest

Hello,

I created a dataset and dataTable in the designer (VB2005) as the datasource
for a Reportviewer control. Up to now I have been creating
dataTables/datasets/dataAdapters on the fly at runtime. But I need to set
field properties on the reportviewer at design time - could probably do it at
run time - but too much code.

So at run time I do this to fill a datatable on the fly
dim da As new sqldataAdapter
dim ds as new dataset
da.selectcommand = new sqlcommand
da.selectcommand.connection = conn
da.selectcommand.commantext = "select * from tbl1")
da.Fill(ds, "tblx")

Now my dataset exists at design time along with the datatable. How do I
fill the existing datatable? the runtime code above complains if I reference
the dataset/dataTable I created at design time. Any suggestions appreciated.

Thanks,
Rich
 
C

Cor Ligthert [MVP]

Rich,

Why do you not use the generated dataset

dim ds as DirectCast(GeneratedDataset as DataSet)

Cor
 
G

Guest

Thanks. I don't understand the idea of using the generated dataset. I tried

Dim ds As DirectCast(GeneratedDataset As Dataset)

but VS complained. So I tried:

Dim ds As DirectCast(Dataset1 As Dataset '--where Dataset1 is the name of
the dataset.

But VS complained about that also. May I request if you could explain in a
little bit more detail about using the generated dataset as you suggest?

Thanks,
Rich
 
C

Cor Ligthert [MVP]

Rich,

What version are you using?

Be aware that I cannot answer you after this before the evening here.

If it is 2003 you have probably somewhere

dim dataset11 as new dataset1 (the generated class you see in your solution
explorer if you open in top show all files)

Than you can use AFAIK that dataset as

dim ds as Dataset = directcast(dataset11, DataSet)

Cor
 
G

Guest

Thank you all for your replies. I am using VB2005.

I create a dataset manually, so in the solution explorer I have
Dataset1.xsd. In the Datasources tab I have my Dataset1 and I add a table
from the toolbox and add the columns manually - this way I can create an rdlc
file for the Report viewer based on the persistent table. But I want to fill
this table using a programmatic dataAdapter - not a TableAdapter from the
toolbox. If I do this:

Dim da As New sqlDataAdpater
Dim ds As DirectCast(Dataset1 As Dataset)

I get the blue squiggly line under DirectCast. I have tried different
variations of

Dim ds As MyProjectName.Dataset1

But VisualStudio(2005) complains. Do I need to use a Namespace maybe? It
seems like the form where I am trying to access Dataset1 just can't see it.
So the question could be - how to make dataset1.xsd visible to my
form/application?

Thanks,
Rich
 
G

Guest

here is some syntax that I tried (which is probably the syntax Cor was
pointing me to)

Dim ds As New Dataset1

Now VS does not complain - although now I have a new issue - which is that I
need the rdlc file to see the dataset in the designer. I will figure that
one out myself.
 
C

Cor Ligthert [MVP]

Rich,

I don't know if this is the error,

Dim ds As Dataset = DirectCast(Dataset1,Dataset)

But this is for sure more the code that is with the directcast

Cor
 
G

Guest

Hi Cor,

Thanks for getting back to me. I keep getting complaints from VS with
dim ds as dataset = directcast(dataset1, dataset)

but if I say

dim ds as new dataset1, then VS does not complain, and I can see the
datatable1 from ds.DataTable1. Also, the report rdcl file appears to work
satisfactory with

report.LocalReport.DataSources.Add(New ResportDataSource("myscr",
ds.datatable1)

I thank you very much for your input as it guided me to what appears to be
the solution.

Rich
 
M

Miha Markic [MVP C#]

Rich,

You don't need to downcast from strongtyped dataset to generic one.
My guess is that you are using type while you should use an instance of that
dataset...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top