Click here to Skip to main content
15,919,613 members
Home / Discussions / Visual Basic
   

Visual Basic

 
AnswerRe: create strings by one giving string Pin
Steve Pullan19-Sep-05 17:54
Steve Pullan19-Sep-05 17:54 
AnswerRe: create strings by one giving string Pin
Steve Pullan20-Sep-05 13:07
Steve Pullan20-Sep-05 13:07 
QuestionInsert values into SQL database from webform Pin
BORN...again!18-Sep-05 15:34
BORN...again!18-Sep-05 15:34 
AnswerRe: Insert values into SQL database from webform Pin
tatchung18-Sep-05 16:09
tatchung18-Sep-05 16:09 
GeneralRe: Insert values into SQL database from webform Pin
BORN...again!18-Sep-05 16:26
BORN...again!18-Sep-05 16:26 
GeneralRe: Insert values into SQL database from webform Pin
tatchung18-Sep-05 16:47
tatchung18-Sep-05 16:47 
AnswerRe: Insert values into SQL database from webform Pin
Edbert P18-Sep-05 20:55
Edbert P18-Sep-05 20:55 
QuestionDatabinding to datagrid Pin
SLG3118-Sep-05 9:23
SLG3118-Sep-05 9:23 
Can anyone help with this one

Have a form with a listbox and 5 textboxes, by clicking the different customer id's in the listbox this then displays the relevant info in the textboxes which is first name, last name, city, state and zip code from the Customers Table, this works fine but I'm trying to display at the same time the orders placed for each selected customerid only in a datagrid from the Orders Table but can't get it to work

The orders placed details to be displayed in the datagrid from the database are OrderID, OrderPrice and CustomerID, have tried to include a data relation but being new to programming not sure if it's right, or which is the correct datasource to use for the datagrid

I also need to show when the form initially loads the info for the first CustomerID by default

Any advice/coding which could help me would be much appreciated, my coding is below

Many thanks

Imports System.Data.OleDb
Imports System.IO

Public Class Form1
Inherits System.Windows.Forms.Form
Dim ds As DataSet

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Declares and instantiates command object
Dim SqlCustomers As String = "SELECT * FROM customers"
'Sets the connection string
Dim connString As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\The Doughnut Shop.mdb"


'Declares and instantiates a new OleDbconnection object
Dim myconnection As OleDbConnection = New OleDbConnection(connString)
' Sets the connection string property
myconnection.ConnectionString = connString
'Declares and instantiates a data adapter
Dim dacustomers As OleDbDataAdapter = New OleDbDataAdapter(SqlCustomers, myconnection)
ds = New DataSet
dacustomers.Fill(ds, "customers")

Dim sqlorders As String = "Select OrderID, OrderPrice, CustomerID from Orders"
' Declares and instantiates the datadapter
Dim daorders As OleDbDataAdapter = New OleDbDataAdapter(sqlorders, myconnection)
daorders.Fill(ds, "orders")

Dim relation As DataRelation = New DataRelation("CustomersOrders", ds.Tables("Customers").Columns("CustomerID"), ds.Tables("Orders").Columns("CustomerID"))
ds.Relations.Add(relation)

ListBox1.DisplayMember = "CustomerID"
ListBox1.DataSource = New DataView(ds.Tables("customers"))


TextBox1.Text = ds.Tables("customers").Rows(0).Item("FirstName")
TextBox2.Text = ds.Tables("customers").Rows(0).Item("LastName")
TextBox3.Text = ds.Tables("customers").Rows(0).Item("City")
TextBox4.Text = ds.Tables("customers").Rows(0).Item("State")
TextBox5.Text = ds.Tables("customers").Rows(0).Item("ZipCode")

End Sub

Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged

Dim drv As DataRowView = CType(ListBox1.SelectedItem, DataRowView)
Dim childRows() As DataRow = drv.Row.GetChildRows("CustomersOrders")


TextBox1.Text = drv("FirstName")
TextBox2.Text = drv("LastName")
TextBox3.Text = drv("City")
TextBox4.Text = drv("State")
TextBox5.Text = drv("ZipCode")

DataGrid1.DataSource = childRows
DataGrid1.Refresh()


End Sub



End Class




AnswerRe: Databinding to datagrid Pin
KaptinKrunch18-Sep-05 17:37
KaptinKrunch18-Sep-05 17:37 
GeneralRe: Databinding to datagrid Pin
SLG3118-Sep-05 22:00
SLG3118-Sep-05 22:00 
QuestionJoystick/Gamepad Pin
Jerry___18-Sep-05 8:28
Jerry___18-Sep-05 8:28 
AnswerRe: Joystick/Gamepad Pin
Christian Graus18-Sep-05 11:05
protectorChristian Graus18-Sep-05 11:05 
GeneralRe: Joystick/Gamepad Pin
Jerry___18-Sep-05 12:05
Jerry___18-Sep-05 12:05 
GeneralRe: Joystick/Gamepad Pin
Christian Graus18-Sep-05 12:12
protectorChristian Graus18-Sep-05 12:12 
GeneralRe: Joystick/Gamepad Pin
Jerry___19-Sep-05 0:32
Jerry___19-Sep-05 0:32 
GeneralRe: Joystick/Gamepad Pin
Dave Kreskowiak19-Sep-05 1:04
mveDave Kreskowiak19-Sep-05 1:04 
GeneralRe: Joystick/Gamepad Pin
Jerry___19-Sep-05 3:06
Jerry___19-Sep-05 3:06 
GeneralRe: Joystick/Gamepad Pin
Dave Kreskowiak19-Sep-05 5:15
mveDave Kreskowiak19-Sep-05 5:15 
GeneralRe: Joystick/Gamepad Pin
Jerry___19-Sep-05 8:48
Jerry___19-Sep-05 8:48 
GeneralRe: Joystick/Gamepad Pin
Jerry___19-Sep-05 9:51
Jerry___19-Sep-05 9:51 
QuestionMDI Pin
JJRW18-Sep-05 3:41
JJRW18-Sep-05 3:41 
AnswerRe: MDI Pin
Dave Kreskowiak19-Sep-05 1:00
mveDave Kreskowiak19-Sep-05 1:00 
Questionbluetooth connection Pin
ecentinela18-Sep-05 1:15
ecentinela18-Sep-05 1:15 
AnswerRe: bluetooth connection Pin
seee sharp18-Sep-05 17:58
seee sharp18-Sep-05 17:58 
GeneralRe: bluetooth connection Pin
ecentinela18-Sep-05 20:29
ecentinela18-Sep-05 20:29 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.