DB/Reporting :: Query On Related Tables?

Nov 15, 2008

I have a simple "two-tables" database (SQL EXpress) and a very simple application (VB 2008 Express). The two tables are customer and order and their structures are:

customer(IDcustomer, LastName, FirstName) IDcustomer=primary key orders(IDord, Number, Description, IDcust)
IDord=primary key the tables are related (IDcustomer-->ID cust)

In VB2008 environment I create a dataset, by means of Data Source Configuration Wizard, which encompass both customer and order tables (xsd file). By opening xsd file I set the relationship in the following manner:

"Both relation and foreign key constraint"
Update Rule = Cascade
Delete Rule = Cascade

In my form I show customer table in detail-mode and orders table in datagridview-mode. Two Fill method are created in the Load event and they work correctly.In "CustomerTableAdapter" I create, with QueryBuilder, a search query (say LastName query) and I write the following code:

Private Sub frmSearch_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.CustomerTableAdapter.FillByLastName(Me.CustomerOrdersDataSet.custom er, "D") 'All Lastnames with first letter = D

[Code]...

View 1 Replies


ADVERTISEMENT

DB/Reporting :: Optimize Query (aggregates On Multiple Tables)?

Feb 20, 2008

Code:

Tables:
- Company
- Department
- Employee
- CertificationA
- CertificationB

I am trying to return a recordset that gives some summary information about each company. The fields in my returned recordset should look like the following.

Company.Name, NumberOfDepartments, NumberOfEmployees, NumberOfCertificationA, NumberOfCertificationACompleted, NumberOfCertificationB, NumberOfCertificationBCompleted

There are actually about 10 different Certification tables but, with Certification A and B you should get the hang of it. When an employee starts a certifaction, a record is added to the that certification table.Below is a query I wrote that works (gets me the data I need), but I am unsure if it is the most efficient way. There will be quite a lot of data so performance is an issue.

Code:

Dim sqlNumberOfDepartments As String
sqlNumberOfDepartments = _
"(SELECT COUNT(*) " & _
"FROM DEPARTMENT " & _

[code].....

View 1 Replies

3 Tier And Related Tables

Dec 14, 2010

I downloaded a 3 tier sample code , but that has no code for related tables, I am trying to complete this.

These are the tables and part of the sample code

[CODE...]

View 2 Replies

How Update Two Related Tables

Dec 11, 2010

i would like to know where is a sample code programmed in 3 tier or n tier to update 2 related tables.

View 7 Replies

Delete Records From Related Tables

Jun 6, 2011

i have 3 tables in ms access that is patient , NOK,and admission they have related fields, i am using vb 2005. when i delete a record from the patient table i want the related records from the other tables to be deleted.

View 1 Replies

Related Tables Update From Datagridview

Mar 1, 2010

[code]I'm able to display Data from the tables to Datagridview but how do I update two tables from Datagridview?For some reason under Advanced Options Generate Insert, update and delete statements gets unchecked.

View 4 Replies

Saving Related Tables And Querying Them?

Nov 9, 2009

I am having a problem saving related tables and querying them. I have both data binding sources on the form and I have both being added, end edit, and both being saved. When I "view all" and click on the related table "crimes" they're not showing with the Inmate that committed them. I have gotten it to do this with a code similar to that below and I am wondering what I'm doing wrong so that the datagridview for crimes will display the correct crimes for the correct inmate. The primary key for inmates is DOC# and the Primary Key for Crimes is "Entry ID"

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
Me.Validate()

[Code].....

View 7 Replies

VS 2010 Primary Key & Related Tables

May 20, 2011

Is there a way to modify the text of a primary key and not have it delete all the following rows in other tables related to it?

View 6 Replies

Related Tables Data Entry Form

Oct 19, 2011

I have a Microsoft Access database that has one-to-many relationships. When I created the tables for the database, I did not enter any data into any records, as that will be done by the application user. My problems is when data is entered into the parent and child tables, the parent table data is the only one that gets saved when clicking the save button on the binding navigator.If I have the parent and child tables data entered the same way a user would prior to connecting the data source and add EndEdit() to the child table BindingSource in the BindingNavigator click event, everything works exactly the way I want it to.This application is a data entry form, so it wouldn't make sense to have to have data entered in tables prior to adding the data source to my project. What is the best way to create a data entry form with one-to-many relationships? [code]

View 6 Replies

Show Data From Two Related Tables In A Datagridview?

Dec 21, 2010

I am trying to produce a form in VB2008 which shows data from two related database tables, and then allows the data in one of the tables to be updated. I would like to do this using a DataGridView, but I have no idea how I would go about this.

View 4 Replies

Sql - Delete The Contents Of A Related Record From Two Tables?

Dec 11, 2011

The StudentDetails.Students is the master table which forms a relationship with RegistrationDetails.Registration. Therefore, StudentID is the primary key in the former whereas it is a foreign key in the latter.Now I've tried each of the following codes but each of the first two gives an error message "Incorrect syntax near 'a'" and in the case of the third one DbTransaction as in "Dim trans As DbTransaction" is also not a valid type. I'm using SQL Server 2008 Professional Edition.

cmd = New SqlCommand("DELETE FROM StudentDetails.Students a, RegistrationDetails.Registration b WHERE (b.StudentId=a.StudentId) AND a.StudentId='" & txtStudentID.Text & "'", cn)

[code]....

View 4 Replies

VS 2010 Save Data In Two Related Tables

Feb 16, 2012

I have a database created using sql server express 2008. There I have two tables called tbl1 and tbl2, which are related as tbl1.CityNumber=tbl2.CityNumber.

I have created the programme using VB 2010; there, a form has three textboxes.

Tables: tbl1,tbl2 ; (related as tbl1.CityNumber=tbl2.CityNumber)
Columns to be updated:tbl1.CityName , tbl1.CityNumber, tbl2.StreetName
TextBoxes on the VB form: txtCityName , txtCityNumber, txtStreetName

[Code]....

But, now the problem is, the two tables have not get updated,after going to the database in MS.SQL Server Management Studio. I think I'm very closer to have my required result. I have tried my best to track place,where I've gone wrong.I have been trying to find a method for last five days.

View 3 Replies

Winforms - Bind A ComboBox To Related Tables?

May 14, 2012

I am developing a Windows Form Application against a SQL Server relational database. An example of the database schema is:

TableA
------------------
PK A_ID uniqueidentifier
A_NAME varchar(254)

[code]....

In the form I have a ComboBox (cboA_ID) to select the TableA record (DataSource = TableA, DisplayMember = A_NAME, ValueMember = A_ID) and a TabControl where controls on each tab are bound to fields in either TableB or TableC.My question is, is it possible to bind cboA_ID to TableB.A_ID and TableC.A_ID?This is my first database application so if there is a better way to do this I'm all ears. I have set everything up using the wizards in Visual Studio 2010, so I'm still not 100% familiar with what all the various TableAdapters and DataSets do.

View 1 Replies

Create A Database That Uses Object Dependencies For Five Different Related Tables?

Feb 9, 2011

I have trying to create a database that uses object dependencies for five different related tables.

View 1 Replies

Delete Contents Of A Related Record From Two Tables( Using SQLTransaction)?

Dec 15, 2011

I'm getting "Format of the initialization string does not conform to specification starting at index 0" error having used the following code. The commands are supposed to delete a related record from two tables namely StudentDetails.Students as the master table and RegistrationDetails.Registration as the child table. [code]...

View 1 Replies

VS 2008 Error - Related Tables - Can't Update Records

Mar 1, 2010

Using a datagrid, binding to one table, and related to one combobos, I cant update records, cause gives me a violation error. I'm not changing the primary key, so, I dont undersatnd cause this happen. I prepair a example of this error, and it was attached to this message.

View 5 Replies

Fill Up A Data Grid View With Records Of Two Related Tables?

Mar 16, 2010

I try to fill up a data grid view with records of two related tables. Beneath you can find the code I use to handle this.

The first table �GemeentenT� has the following columns.

GemeenteId Primary key
GemeentePostnummer
GemeenteNaam

[Code].....

View 5 Replies

Combobox Query - SelectedIndexChanged And SelectionChangeCommitted Related?

Oct 7, 2009

I'm designing a login screen which MUST allow the user to ONLY select a login via a combobox. A user has THREE login attempts only, the problem Im experiencing is resetting the count if they hilight the combobox, move the selection around but ultimately click on the original name.I can use either SelectedIndexChanged or SelectionChangeCommitted but they are both activated even if the same login is selected.So you can select a login enter the password twice and then click on the combobox move the selection around before finally clicking the original name and the login count is reset to 0.Is their a way to do this without using variables to store the previous value (perhaps using validating/validation methods)?

View 4 Replies

Export To Excel 3 Related Tables Into Excel?

Aug 22, 2010

I'm a beginner to VB.net. I have 3 table (Torder, Titem, Customer)Table structure as below.

Order.dbf fields (OrderNo, CustCode)
Titem.dbf fields (OrderNo, Itemno, product)
Customer.dbf fields (CustCode, CustName)

Torder related to Titem via Order No. Customer related to Torder via CustCode. How to output data to excel sheet in this format?

View 4 Replies

DB/Reporting :: Dataset With Two Tables

Feb 22, 2010

I am trying to develop a report that displays the result of a query that returns two tables. The first table is always a single row of values, the second should be a grid. I can get a report to display either independently, however it will not allow me put them both on the same report.

View 1 Replies

DB/Reporting :: Join Two Tables IN SQL?

Jun 16, 2010

I am working on a Visual Basic 2008 program using an Access 2000 database. My SQL codereturns no records, but I know the table has a record. A simplified example of the code looks like this:

SELECT Table1.Field1, Table1.Field2, Table1.Field3, Table1.Field4, Table2. Field1, Table2.Field2 FROM Table1 INNER JOIN Table2 ON Table1.Field1 = Table2.Field1 AND Table1.Field2 = Table2.Field2 WHERE Table1.Field1=@Field1 AND Table1.Field2=@Field2;

[code].....

View 2 Replies

DB/Reporting :: Delete From Multiple Tables?

Feb 6, 2009

I need to write and SQL query that three from three linked tables. Basically there is a 'case_id' column in each table with matching values.

What I have is:

Code:
declare @archiveYears int
set @archiveYears = -7
delete from cw_ht_bacase where case_id in (

[Code]....

As you can see I have the same query in the "in" clause for each statement. Is there a way to normalise this, sort of like C macro. Basically I'd just to define the inner select statement once and use it multiple times.

View 5 Replies

DB/Reporting :: Relations Between Two Tables - CustID

Feb 20, 2010

Lets assume that I have 2 tables:
First one is customer table and has primary key called cusid ( auto increment)
Second one is order table and has foreign key custid

How I can connect them, what I mean exactly when insert the record in the customer table I need the foreign key get the same value as primary key in customer table. I'm using sql server 2008 and vb.net 2008.

View 1 Replies

DB/Reporting :: Update 8 Tables In A Transaction?

Apr 25, 2011

I have an application which upon a save button needs to save data to 8 different tables. 7 of those tables will have multiple new records added to them, while 1 will have just one new record. I want to encapsulate this giant Insert operation in a Transaction so that it will not complete unless I can save successfully to all tables.I have considered using Insert commands to a command statement, but adding what amounts to like 50 parameters, and the fact that using a parameterized query means it becomes very difficult to troubleshoot problems such as invalid values in the SQL statement (since I cannot figure out what the statement looks like with values in it

View 3 Replies

DB/Reporting :: Creating Crystal Report From Two Tables?

Dec 20, 2011

I am trying to load a crystal report from two tables but it seems that is not working.Here is the code to load the crystal report:

Code:
Private Sub InvoiceLoad(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

[code]......

View 1 Replies

DB/Reporting :: How To Create/update Tables Programmatically

Nov 10, 2008

A suite of apps will be using various tables out of the same sql server database.Regardless of which app is being used, the database structure must stay current. (ie:contain all the tables/fields to run any/all of the apps)So, when the user starts any of the apps, it needs to check the database, for the existence of all the tables and fields it needs, then update if necessary.

View 1 Replies

DB/Reporting :: Relation Between Two Similar Data In Two Tables?

Oct 9, 2008

I want to make relationship between them Where In the F column of Table2 will sum the numbers in F column of table 3 according this condition ( show in the pic.)For the same data in columns(B,C,D) between two tables Example: Table 2 include in B,C,D data HH XX FF There are many data (HH XX FF) in tables3 in same columns(b,c,d) so it will sum the numbers in F column that in the same row with the data (HH xx FF), and insertded the results in the in table2 in F colmn in the same row with (HH XX FF)

View 10 Replies

DB/Reporting :: Database Explorer In VBe 9.0(2008) W/ Foxpro Tables?

Nov 22, 2009

So Im working on updating our company's program from Visual FoxPro to VB and this is the first step. I can access and read data from the table

Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

[code].....

View 1 Replies

SQL Query From 3 Tables?

Aug 15, 2011

I am having difficulty with a SQL query in my project.I have 3 tables.

T1:
- Date
- ID
- Location_ID

[code]....

From this I need the T1.Date and T3.Result based on Location in T2.So my I need a query to compare a known location, get the Location_ID. Then Use that Location_ID to get the Date and ID. Use the ID to get the Result from T3. (Value is a variable with the known Location)

This is what I have tried:

"SELECT T1.Date,T3.Result _
FROM T1,T2,T3 _
WHERE T1.Location_ID = (SELECT T2.Location_ID FROM T2 WHERE T2.Location = '" & Value & "') AND T3.ID = (SELECT T1.ID FROM T1 WHERE
T1.Location_ID = (SELECT T2.Location_ID FROM T2 WHERE T2.Location = '" & Value & "'))"

I get the error 'Sub query returns more than 1 value...'

View 6 Replies

Sql Query With Many To Many Tables?

Dec 22, 2010

I'm using VB.Net express with an Access file, and I have the following tables:

table Formula
id | name
-------------------
1 | formula 1[code]....

So each formula have one or more components.Which query will I use if I want all the formulas with for example Component A AND Component D (Result: formula 1, formula 2)? I try something with intersect, but it seems it doesn't work in VB...

View 2 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved