vb.net create tabpages and datagridview from list exported from SQL - vb.net

Just after some ideas on the best way to create additional tabpages dynamically within a tabcontrol and also to then add the relevant data on each tab with a datagridview.
The tabcontrol will always exist, but I'm not sure whether to initially create the additional tabpages first by identifying the distinct data in SQL, and then run a further script to extract the data, which then needs to be added to the datagridview, or whether I can use vb.net to create the distinct tabpages and add the data from one table, as below.
I can add another tabpage dynamically but not sure the best way to do it for a list, that is extracted from SQL.
Hope that makes sense. Thanks
TabCode
TabName
DataName
DataType
1
One
Test Name
Text
1
One
Test Date
Date
2
Two
Test Value
Value
I've managed to create new tabpages, but only single instances as not sure how to create them from a list extracted from SQL. I'm then struggling to add the data to the relevant datagridview, which I envisage would be created with a name linked to the tabpage name.

Related

How to pass data from DataGridView to table in ReportViewer without Database or Dataset

I have a few DataGridView tables which user fills (I don't use any Dataset or Database here).
I need to pass them to ReportViewer, I want exact the same tables in report as in a form, no changes at all.
I tried something like this, but it's not working:
Dim rds As New ReportDataSource("rds1", Form1.dgv1.DataSource)
Me.ReportViewer1.LocalReport.DataSources.Add(rds)
and in report1.rdlc added a table and set it dataset name to rds1 but it generates error
The table ‘table1’ refers to an invalid DataSetName ‘rds1’.
So I guess I need to make a DataSet from my DataGridView tables.
How would you suggest me to do that? Otherwise, is there any simpler way to pass the table to report?
You should add a DataSet to your report .rldc Data Sources list and drag and drop the columns into your report element (table, tablix, list etc.)
Remember you can add any kind of object from your project to your report as Data Source (basically any Public Class you create). The imported names and types will be taken from the class properties.

What are different ways in VB Dot Net to populate DataGridView Grid using SQL Query?

I want to populate a DataGridView Grid in my Form with Data from SQL Query or from some Table form Database. I want to know various possible ways to populate the DataGridView Grid.
Thanks in advance.
There are basically 3 ways to display data in a DataGridView
Create the rows manually in a loop: it's very inefficient if you have a lot of data
Use the DataGridView's virtual mode: the DGV only creates as many rows as can be displayed, and
dynamically changes their contents when the user scrolls. You need
to handle the CellValueNeeded event to provide the required data to
the DGV
Use databinding: that's by far the easiest way. You just fill a
DataTable with the data from the database using a DbDataAdapter, and
you assign this DataTable to the DGV's DataSource property. The DGV
can automatically create the columns (AutoGenerateColumns = true),
or you can create them manually (you must set the DataPropertyName
of the column to the name of the field you want to display). In
databound mode, the DGV works like in virtual mode except that it
takes care of fetching the data from the datasource, so you don't
have anything to do. It's very efficient even for a large number of
rows
Link.

creating a ComboBox in MS Access to hold distinct types

I am trying to create a combo box in an Access form to display all the types in an inventory list (ex. cables, UPS, shelves, ...)
When I make the row source for the ComboBox I only want the type to display there once. The ComboBox will later be used to make a report for the different types of items in the inventory, so I will only need each type in the list box once. These types can be changed later so I want the list to be updated automatically.
Right now I have the ListBox displaying all the types multiple times, but when I try to change the row source to:
Select Distinct Inv_Type
From Inventory;
I just get an empty ComboBox. But when I query that code I get get each type only once (this is what I want). What am I doing wrong? Why am I getting an empty ComboBox?
Doing as what Remou said; I created a ComboBox from scratch, without using the wizard first fixed my problem. Thanks!

how to populate textbox with the database value based on combobox change in access

I am new to Access and vb and i have failed to get the result what i am thinking to get ,hope i will resolve with your help guys
->my access database contains one table with following fields
firstname lastname middlename phone
I have two combo boxes and two textboxes
combobox- it populates firstname and based on this selection the other combo box has to fill with last name which i did successfully with the help of Me.Combo2.Requery
but i dont know how to fill middle and phone in textboxes
here i am failing in mapping recordset and connectionstring with my table and getting result to textbox value can any one help on this
You still have not said where the connection string comes from or why. The big advantage of Access is that it is fast and easy, for the most part, you do not need connection strings.
First, select your table, then choose create form. This will create a single form bound to the table. You could have created a query first and chosen that instead.
That is it. You have a form that displays your data. The key to this is the property sheet for the form, which you can find by switching to design view and double-clicking the small square at the top left of the form just under the form name. The property sheet will show the name of the table or query on the Data tab under the Record Source propery. You can, of course, set this property manually.
You can now add a combobox to select records, but you do not have to, there are navigation buttons at the bottom of the form.
To add a combobox that selects records on your form, you must have first bound a recordset to your form using the steps above. Next, ensure that the wizard is selected for the toolbox. Unless you have unselected it, it will be selected. Now choose combobox from the toolbox, it will open the wizard.
Choose find a record on my form and press next to choose the relevant ID field / column and any other fields that you need. When the wizard completes, in MS Access 2010 (and probably in 2007) it will add an embedded macro that finds your record and in earlier versions it will add code. Other properties set by the wizard will look something like this:
Row Source : SELECT ID, Firstname, Lastname FROM Table1
Column Count : 3
Column Widths : 0cm;2.54cm;2.54cm
Your table should have an ID, add one before you start, if it does not. The wizard will not add a Control Source when this option is selected because it is not needed, in fact, it would be a disaster to add a Control Source to a combo that finds records. Once again, you can do this manually. The code to find a record might look something like:
Private Sub MyCombo_AfterUpdate()
With Me.Recordset
.FindFirst "ID=" & Me.MyCombo
End With
End Sub
This works because the bound column of the combo is set to 1, the first field of the select statement, which is ID.
The combo includes two other fields / columns and you can refer to these in a textbox by setting the control source of the textbox to:
= MyCombo.Column(2) ''Lastname
Where you count columns from zero:
Row Source : ID (0), Firstname (1), Lastname (2)
Cascading combos are another story altogether, and you can read it here How to synchronize two combo boxes on a form in Access 2002 or in Access 2003 and here Is there a simple way of populating dropdown in this Access Database schema?

binding textboxes to a table

I have two tables that are related to each other in a 1-1 relationship (each row in the main table has exactly one corresponding row in the second table).
I also have a winform in which I'd like to show the main table in a datagridview, and for each row selected in the grid to show the fields of the corresponding row of the second table in various textboxes below the grid.
I know how to bind a datagridview to a datatable. But I'm not sure about binding several textboxes to a single row in the related datatable. I don't know what is the best way to implement it.
I'm writing in VB.Net (but can read some code in C#), using VS2008.
Any help, hints or ideas will be welcomed. Thanks.
Best way to do it is that instead of using two tables, use a join and get result in a single table, bind that table to gridview, and hide columns which you don't want to display to user.
And then use cell click event of gridview and then get the index of selected row and then use
txtBoxName.Text = GridViewName["col_name",e.RowIndex].Value.ToString();