VS reportviewer how do i create a rdlc file - reportviewer

I am new to reportviewer and struggling with the concepts.
I realise that I am probably being very stupid here. I have tried reading up on the reportviewer but not found any tutorials except those that drag and drop datasets. which is not what I want to do.
I want to create a report from a single datatable at first just as a learning exercise.
I have created a dataset added the table to it and have tried this code but I get an error: 'The report definition for report "C:\Users\Mike\BM\Reports\" has not been specified. Object reference not set to an instance of an object'
I don't really understand what the 'The report definition' bit means?
I would appreciate some guidance please.
Dim MyTestDS As New DataSet
Dim myTestTable As New DataTable
myTestTable = Data.Accounts.Table.Copy
MyTestDS.Tables.Add(myTestTable)
Dim DSReport As New ReportDataSource()
DSReport.Name = "MyTestDS"
DSReport.Value = MyTestDS.Tables(0)
Dim PathReport As String = "C:\Users\Mike\BM\Reports\"
ReportViewer1.LocalReport.ReportEmbeddedResource = PathReport
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.DataSources.Add(DSReport)
ReportViewer1.LocalReport.Refresh()
ReportViewer1.RefreshReport()

As a learning exercise, I think is better not using embedded resource so you can simply specify the complete report path of your rdlc file; for example:
ReportViewer1.LocalReport.ReportPath = "C:\Users\Mike\BM\Reports\YourReportFile.rdlc"
If you want to use an embedded report, I think you have to get it like this:
Get Embedded Resource

Copy YourReportFile.rdl to YourReportFile.rdlc

Related

System.Web.Services cannot be added to VB.NET project in Visual Studio

I am working on a VB.NET project in Visual Studio Community 2019, using Windows forms. I want to populate a DataGridView with data from a DataSet. But I get an error upon creating the DataSet, saying that "System.Web.Services could not be added to the project". The DataSet is then created, but I cannot chose it as a DataSource for the DataGridView. Maybe it is worthwhile to mention that my project is not intended to deal with anything online, so I wonder why should I need any Web Service stuff. How I can get rid of the error, or at least populate the DataGridView with my DataSet?
I am noticing -thanks Jon!- the following in the VB code (some 600 auto-generated lines) belonging to the DataSet:
Me.DataSetName = "DataSet1"
Me.Prefix = ""
Me.Namespace = "http://tempuri.org/DataSet1.xsd"
and further down:
Dim any1 As Global.System.Xml.Schema.XmlSchemaAny = New Global.System.Xml.Schema.XmlSchemaAny()
any1.Namespace = "http://www.w3.org/2001/XMLSchema"
I do not know how to bind the data to the grid view by hand, I was trying to use the GUI for doing it, which is not offering me the DateSet as source.
For the DataGrid view, I dragged it in from the toolbox where it can be found under "All Windows Forms"->"DataGridView".
worked now around the GUI way of creating a DataSet by
creating an xml which I can load as DataSet
<NewDataSet>
<Table0><col0>entry0row0</col0><col1>entry1row0</col1></Table0>
<Table0><col0>entry0row1</col0><col1>entry1row1</col1></Table0>
</NewDataSet>
reading in the xml by:
Imports System.xml
ds = New DataSet
Using xmlFile As XmlReader = XmlReader.Create(filename, New XmlReaderSettings())
ds.ReadXml(xmlFile)
End Using
DataGridView1.DataSource = ds.Table(0)

CAML query not retrieving all fields using vb.net VS2019 and Sharepoint online

I was asked to write an app at work that grabs an Employee list from our Sharepoint online site for eventual auto updating. The part I am stuck on is retrieving all of the fields of my employee list.
I would think that my query would simply bring back all of the fields that I see on my sharepoint list. But I admit that at this point that I do not have the best understanding of CAML.
So, I start to loop through each item in my Allitems object to create a datarow for each row of info so I can have a nice little data-table to display to the user. When the line of code runs to find item.("First Name") , I get the message that it is not in the list and that I may need to explicitly query it. Same with all of the other fields with a space. My AllItems object is bringing back all columns with the names that do not have a space (ie. Department, Title, Location, Email) which is strange to me.
Apparently, I do not understand Sharepoint enough and what the fields are called with a space.
I also see some C# examples with another method for the query object : query.ViewFields . I do not have this option for my query object. Also, can someone recommend another Sharepoint imports that would be beneficial here besides the ones that I am using?
Any help and advice would be greatly appreciated. Even an entirely different way of getting this data would be appreciated.
Also, I left only 4 of the datarow fields in the below code since it is failing on "First Name" to keep the code uncluttered. Since that would be the same reason for all of the other fields that are not comming back in my query.
Chris
Imports Microsoft.SharePoint
Imports Microsoft.SharePoint.Client
Try
Dim cred = New SharePointOnlineCredentials(txtUserName.Text, secureString)
Dim ctx = New Microsoft.SharePoint.Client.ClientContext(siteUrl)
ctx.Credentials = cred
Dim web As Web = ctx.Web
Dim list As List = web.Lists.GetByTitle(siteList)
ctx.Load(list)
ctx.ExecuteQuery()
Dim query As CamlQuery = CamlQuery.CreateAllItemsQuery()
query.ViewXml = "<View Scope='RecursiveAll'><Query><ViewFields><FieldRef Name='First Name'/><FieldRef Name='Last Name'/><FieldRef Name='Office Phone'/><FieldRef Name='Email'/><FieldRef Name='Cell Phone'/><FieldRef Name='Department'/><FieldRef Name='Location'/></ViewFields></Query></View>"
Dim AllItems As ListItemCollection = list.GetItems(query)
ctx.Load(AllItems)
ctx.ExecuteQuery()
If AllItems.Count > 0 Then
Dim dt As New DataTable
Dim dRow As DataRow
Dim dcID As New DataColumn("Id")
dcID.DataType = Type.GetType("System.String")
Dim dcFName As New DataColumn("First Name")
dcFName.DataType = Type.GetType("System.String")
Dim dcLName As New DataColumn("Last Name")
dcLName.DataType = Type.GetType("System.String")
Dim dcTitle As New DataColumn("Title")
dcTitle.DataType = Type.GetType("System.String")
dt.Columns.Add(dcID)
dt.Columns.Add(dcFName)
dt.Columns.Add(dcLName)
dt.Columns.Add(dcTitle)
For Each item As ListItem In AllItems
dRow = dt.NewRow()
dRow("Id") = item.Id
dRow("First Name") = item("First Name")
dRow("Last Name") = item("Last Name")
dRow("Title") = item("Title")
dt.Rows.Add(dRow)
Next
DGVList.DataSource = dt
End If
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
Ok, it seems that the CAML was correct. I just did not know the internal names on the Sharepoint site. Once I obtained a list of the internal field names (not the display ones like I naively thought), I no longer ran into any errors. The answer was not so hard once I realized that I was querying fields that did not exist. It makes perfect sense that Visual Studio would yell at me for it.

Passing data from a Datagrid to Report Viewer

I'm relatively new to form programming in Visual Basic and need some help.
I've successful got what I want from my database into a datagrid but need this in a report viewer.
dgvReport.DataSource = dsReport
Dim ds As DataTable = New DataTable("GenerateReport")
Dim ReportDataSource = New ReportDataSource("GenerateReport", ds)
rvReport.LocalReport.DataSources.Clear()
rvReport.LocalReport.DataSources.Add(ReportDataSource)
rvReport.LocalReport.ReportEmbeddedResource = "Test.Report1.rdlc"
rvReport.RefreshReport()
Where 'dsReport' is the name of the dataset I'm using.
'Generate Report' is the table name within the dataset.
"Test.report1.rdlc" is the path of the report file.
I've searched and found this code, but the error I get says that the the program cannot find the file. I was unaware that there's a file saved which you then copy the data from into the report viewer.
I don't know if this is right, what I'm doing. Any help is much appreciated.

Exporting Report From VB.net

Is there a way to export data that has been populated into a VB.net forms application split by Tabs? I have a large program that connects to a SQL database and runs many queries to populate Labels within the application.
I would like to export the data into an Excel Sheet over different tabs per Tabular Page in the Form application. If this is not possible then a generic .csv export will be fine.
I am running my SQL query and importing it into Labels like this -
Dim myCmd23 As New SqlCommand("MySQL Query", myconn)
Dim myDataA23 As New SqlDataAdapter(myCmd23)
Dim myDataT23 As New DataTable()
Dim myDataS23 As New DataSet()
myDataA23.Fill(myDataT23)
DataGridView1.DataSource = myDataT23
Dim result23(2) As String
result23(1) = DataGridView1.Rows(0).Cells(0).Value.ToString
result23(2) = DataGridView1.Rows(0).Cells(1).Value.ToString
Label1.Text = result23(1)
Label2.Text = result23(2)
There are many of these SqlCommands carried out. The Form application looks like such -
The seperate tabs are shown above and i would like to try and seperate this data in the Export?
The Dates and Filters are taken into account within each seperate SQL query so they are no bother.
If anybody has a possible solution that would be great.
Thanks
Greg
There are several blogs about exporting datatables to Excel in VB.NET here

how to query/get data from Datasource in VB.NET

i am building a database application in vb.net and i started by adding a data source from the DATA in the toolbar. my connection is good and it shows all my tables in the data source panel.
i also see new classes related to my database, like
sakilaDataSet
sakilaDataSet.customerDataTable
...
and so on.
how do i query and use these ? i googled a lot and i am not able to get this.
Dim cust As sakilaDataSet.customerDataTable = New sakilaDataSet.customerDataTable
Dim row() As System.Data.DataRow = cust.Select("customer_id=5")
MsgBox(row.Count)
My last try was with the above code, but the row.count always turns out to be zero.
You need to open a connextion to the DB. Here are some options:
You could use EntityFramework, which provides a nice way to access data and control it by mapping to entities (classes). For this, in VisualStudio create a ClassLibrary project, add an item ADO.NET Entity Data Model. This will open a wizard that will help you connect to the DB, map the objects in the DB to entities and access the entities by a reference to an entity context. The basics are easy.
Other option is to use an OLEDB provider, which is a classic way to access DB. An example to open an Access DB of employees:
Dim connString As String = "provider= microsoft.jet.oledb.4.0; " & _
"data source=Employee.mdb;"
Dim conn As New OleDbConnection(connString)
Try
conn.Open()
Finally
conn.Close()
Console.WriteLine("Connection Closed")
End Try
Visit http://www.connectionstrings.com/ to get a list of common connection string for many DB. Other useful links:
EntityFramework:
http://www.codeguru.com/csharp/csharp/net30/article.php/c15489
http://www.asp.net/entity-framework/tutorials
OLEDB:
http://oreilly.com/catalog/progvbdotnet/chapter/ch08.html
http://www.homeandlearn.co.uk/net/nets12p2ed.html
http://www.sourcecodester.com/tutorials/net/database-programming-made-easy.html
Hope this helps.
What i wanted to achieve was not to use connection strings again. After adding the data source in VB.net, it makes Data Classes and Adapters, which i can use directly to access the database, as follows :
Dim staff As sakilaDataSet.customerDataTable = New sakilaDataSetTableAdapters.customerTableAdapter().GetData
Dim rows() As sakilaDataSet.customerRow = staff.Select("email='" + email.Text + "'")
This website http://visualbasic.about.com/od/usingvbnet/a/begdbapp7.htm had a good tutorial where it talked about what happens when you use the data sources window and how to use it in your code after that.
I know it's an old question, but it was very high in Google results, and it was more of a "This is how you should have done it" answer instead of actually answering with what it seems like you asked