Help needed using a datagrid to show customer orders

diverdan

Active member
Joined
Jan 2, 2006
Messages
34
Location
London UK
Programming Experience
Beginner
Good afternoon.

I am hoping someone can help me out with a problem that I cant fix on my own.

I have created a form that contains customer details. I have also added a datagrid that I want to be able to view all the customer orders.

I am using an sql database with the following tables tblCustomers & tblOrders. tblOrders has a FK customerID to create the join.


What do I need to do to get this to work.


This is my code I am using to populate my form currently.

VB.NET:
[SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Data
[/SIZE][SIZE=2][COLOR=#0000ff]Imports[/COLOR][/SIZE][SIZE=2] System.Data.SqlClient
 
 
[/SIZE][SIZE=2][COLOR=#0000ff]Public[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Class[/COLOR][/SIZE][SIZE=2] frmCustomers
[/SIZE][SIZE=2][COLOR=#0000ff]Inherits[/COLOR][/SIZE][SIZE=2] System.Windows.Forms.Form
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] objConnection [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] SqlConnection = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] _
SqlConnection([/SIZE][SIZE=2][COLOR=#800000]"server= nx6130;database=actionglass;user id=sa;Trusted_Connection=True;"[/COLOR][/SIZE][SIZE=2])
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] objDataAdapter [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] SqlDataAdapter = [/SIZE][SIZE=2][COLOR=#0000ff]New[/COLOR][/SIZE][SIZE=2] SqlDataAdapter( _
[/SIZE][SIZE=2][COLOR=#800000]"SELECT tblCustomers.CustomerName,ContactName,PhoneNumber,FaxNumber,MobNumber,EmailAddress,Address1,Address2,Address3,Address4,DAddress1,DAddress2,DAddress3,DAddress4,Comments,CustomerID "[/COLOR][/SIZE][SIZE=2] & _
[/SIZE][SIZE=2][COLOR=#800000]"FROM tblCustomers "[/COLOR][/SIZE][SIZE=2] & _
[/SIZE][SIZE=2][COLOR=#800000]"ORDER BY CustomerName"[/COLOR][/SIZE][SIZE=2], objConnection)
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] objDataSet [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataSet
[/SIZE][SIZE=2][COLOR=#0000ff]Dim[/COLOR][/SIZE][SIZE=2] objDataView [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] DataView[/SIZE]
[SIZE=2][/SIZE] 
[SIZE=2][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] frmCustomers_Load([/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] sender [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.Object, [/SIZE][SIZE=2][COLOR=#0000ff]ByVal[/COLOR][/SIZE][SIZE=2] e [/SIZE][SIZE=2][COLOR=#0000ff]As[/COLOR][/SIZE][SIZE=2] System.EventArgs) [/SIZE][SIZE=2][COLOR=#0000ff]Handles[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]MyBase[/COLOR][/SIZE][SIZE=2].Load
[/SIZE][SIZE=2][COLOR=#0000ff]Me[/COLOR][/SIZE][SIZE=2].WindowState = FormWindowState.Maximized
FillDG()
FillDataSetAndView()
BindFields()
[/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff][/COLOR][/SIZE] 
[SIZE=2][COLOR=#0000ff][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] BindFields()
txtCustomerName.DataBindings.Clear()
txtCustomerName.DataBindings.Add([/SIZE][SIZE=2][COLOR=#800000]"Text"[/COLOR][/SIZE][SIZE=2], objDataView, [/SIZE][SIZE=2][COLOR=#800000]"CustomerName"[/COLOR][/SIZE][SIZE=2])
txtContactName.DataBindings.Clear()
txtContactName.DataBindings.Add([/SIZE][SIZE=2][COLOR=#800000]"Text"[/COLOR][/SIZE][SIZE=2], objDataView, [/SIZE][SIZE=2][COLOR=#800000]"ContactName"[/COLOR][/SIZE][SIZE=2])
txtPhoneNumber.DataBindings.Clear()
txtPhoneNumber.DataBindings.Add([/SIZE][SIZE=2][COLOR=#800000]"Text"[/COLOR][/SIZE][SIZE=2], objDataView, [/SIZE][SIZE=2][COLOR=#800000]"PhoneNumber"[/COLOR][/SIZE][SIZE=2])
txtFaxNumber.DataBindings.Clear()
txtFaxNumber.DataBindings.Add([/SIZE][SIZE=2][COLOR=#800000]"Text"[/COLOR][/SIZE][SIZE=2], objDataView, [/SIZE][SIZE=2][COLOR=#800000]"FaxNumber"[/COLOR][/SIZE][SIZE=2])
txtMobNumber.DataBindings.Clear()
txtMobNumber.DataBindings.Add([/SIZE][SIZE=2][COLOR=#800000]"Text"[/COLOR][/SIZE][SIZE=2], objDataView, [/SIZE][SIZE=2][COLOR=#800000]"MobNumber"[/COLOR][/SIZE][SIZE=2])
txtAddress1.DataBindings.Clear()
txtAddress1.DataBindings.Add([/SIZE][SIZE=2][COLOR=#800000]"Text"[/COLOR][/SIZE][SIZE=2], objDataView, [/SIZE][SIZE=2][COLOR=#800000]"Address1"[/COLOR][/SIZE][SIZE=2])
txtAddress2.DataBindings.Clear()
txtAddress2.DataBindings.Add([/SIZE][SIZE=2][COLOR=#800000]"Text"[/COLOR][/SIZE][SIZE=2], objDataView, [/SIZE][SIZE=2][COLOR=#800000]"Address2"[/COLOR][/SIZE][SIZE=2])
txtAddress3.DataBindings.Clear()
txtAddress3.DataBindings.Add([/SIZE][SIZE=2][COLOR=#800000]"Text"[/COLOR][/SIZE][SIZE=2], objDataView, [/SIZE][SIZE=2][COLOR=#800000]"Address3"[/COLOR][/SIZE][SIZE=2])
txtAddress4.DataBindings.Clear()
txtAddress4.DataBindings.Add([/SIZE][SIZE=2][COLOR=#800000]"Text"[/COLOR][/SIZE][SIZE=2], objDataView, [/SIZE][SIZE=2][COLOR=#800000]"Address4"[/COLOR][/SIZE][SIZE=2])
txtDAddress1.DataBindings.Clear()
txtDAddress1.DataBindings.Add([/SIZE][SIZE=2][COLOR=#800000]"Text"[/COLOR][/SIZE][SIZE=2], objDataView, [/SIZE][SIZE=2][COLOR=#800000]"DAddress1"[/COLOR][/SIZE][SIZE=2])
txtDAddress2.DataBindings.Clear()
txtDAddress2.DataBindings.Add([/SIZE][SIZE=2][COLOR=#800000]"Text"[/COLOR][/SIZE][SIZE=2], objDataView, [/SIZE][SIZE=2][COLOR=#800000]"DAddress2"[/COLOR][/SIZE][SIZE=2])
txtDAddress3.DataBindings.Clear()
txtDAddress3.DataBindings.Add([/SIZE][SIZE=2][COLOR=#800000]"Text"[/COLOR][/SIZE][SIZE=2], objDataView, [/SIZE][SIZE=2][COLOR=#800000]"DAddress3"[/COLOR][/SIZE][SIZE=2])
txtDAddress4.DataBindings.Clear()
txtDAddress4.DataBindings.Add([/SIZE][SIZE=2][COLOR=#800000]"Text"[/COLOR][/SIZE][SIZE=2], objDataView, [/SIZE][SIZE=2][COLOR=#800000]"DAddress4"[/COLOR][/SIZE][SIZE=2])
txtEmailAddress.DataBindings.Clear()
txtEmailAddress.DataBindings.Add([/SIZE][SIZE=2][COLOR=#800000]"Text"[/COLOR][/SIZE][SIZE=2], objDataView, [/SIZE][SIZE=2][COLOR=#800000]"EmailAddress"[/COLOR][/SIZE][SIZE=2])
txtCustomerID.DataBindings.Clear()
txtCustomerID.DataBindings.Add([/SIZE][SIZE=2][COLOR=#800000]"Text"[/COLOR][/SIZE][SIZE=2], objDataView, [/SIZE][SIZE=2][COLOR=#800000]"CustomerID"[/COLOR][/SIZE][SIZE=2])
txtComments.DataBindings.Clear()
txtComments.DataBindings.Add([/SIZE][SIZE=2][COLOR=#800000]"Text"[/COLOR][/SIZE][SIZE=2], objDataView, [/SIZE][SIZE=2][COLOR=#800000]"Comments"[/COLOR][/SIZE][SIZE=2])
 
ShowPosition()
StatusBar1.Text = [/SIZE][SIZE=2][COLOR=#800000]"Ready"
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff][/COLOR][/SIZE] 
[SIZE=2][COLOR=#0000ff][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]Private[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE][SIZE=2] FillDG()
grdInvoices.DataSource = objDataSet
grdInvoices.DataMember = [/SIZE][SIZE=2][COLOR=#800000]"tblcustomers"
 
[/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff]End[/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff]Sub[/COLOR][/SIZE]
[SIZE=2][COLOR=#0000ff]
[/COLOR][/SIZE]

Can anyone suggest what I need to do to get this working?
[/COLOR][/SIZE][/COLOR][/SIZE][/SIZE]
 
Back
Top