Whats wrong with this code ?

  • Thread starter Thread starter Terry Burns
  • Start date Start date
T

Terry Burns

I have two data adapters and tables (people and events ). The People have a
unique key and the Events also. In the Events the ID fiels corresponds with
the ID PKEY of the People.

Basically, when you initialise this, the People grid fills but the Events do
not fill with the matching ID rows.



Help would be great - Terry



Sub initialiseDataConnectivity()

Dim cmd As New OleDbCommand

' set connection string

con.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet
OLEDB:Registry Path=;Jet OLEDB:Database L" & _

"ocking Mode=1;Data Source=""C:\Documents and Settings\Administrator\My
Documents\" & _

"FamilyPlusFriends.mdb"";Jet OLEDB:Engine
Type=5;Provider=""Microsoft.Jet.OLEDB.4.0" & _

""";Jet OLEDB:System database=;Jet OLEDB:SFP=False;persist security
info=False;Ext" & _

"ended Properties=;Mode=Share Deny None;Jet OLEDB:Encrypt Database=False;Jet
OLED" & _

"B:Create System Database=False;Jet OLEDB:Don't Copy Locale on
Compact=False;Jet " & _

"OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Global
Bulk T" & _

"ransactions=1"

'open connection

con.Open()

'Initialise People

dgPeople.DataSource = tablePeople

cmd.CommandText = "SELECT ID,FirstName,LastName,DOB,[Mobile Fone],[Home
Phone],Email, Address1, Address2,Address3, Address4,Town, [Post Code],
County, Country,MiddleInnitial FROM(People)ORDER BY FirstName"

cmd.CommandType = CommandType.Text

cmd.Connection = con

daEvents.SelectCommand = cmd

daEvents.Fill(tablePeople)



'Initialise Events

dgEvents.DataSource = tableEvents

cmd.CommandType = CommandType.Text

cmd.CommandText = "SELECT * FROM Events WHERE id=?"

cmd.Connection = con

cmd.Parameters.Add("@ID", OleDbType.Integer).Value =
dgPeople.Item(dgPeople.CurrentRowIndex, 0)

daEvents.SelectCommand = cmd

daEvents.Fill(tableEvents)





'Close connection

con.Close()
 
There's no client side relation to make them correspond
to each other (unless you have it defined elsewhere).

Check out the BindingManager , BindingmanagerBase and
DataRelations in help
http://msdn.microsoft.com/library/default.asp?
url=/library/en-
us/cpref/html/frlrfSystemDataDataRelationClassTopic.asp

You can also implement it with dataview which can get the
job done too....depends on how you want to do the update.

I can walk you through it if you have trouble after
checking out the BindingManager.

Good Luck,

Bill
-----Original Message-----
I have two data adapters and tables (people and events ). The People have a
unique key and the Events also. In the Events the ID fiels corresponds with
the ID PKEY of the People.

Basically, when you initialise this, the People grid fills but the Events do
not fill with the matching ID rows.



Help would be great - Terry



Sub initialiseDataConnectivity()

Dim cmd As New OleDbCommand

' set connection string

con.ConnectionString = "Jet OLEDB:Global Partial Bulk Ops=2;Jet
OLEDB:Registry Path=;Jet OLEDB:Database L" & _

"ocking Mode=1;Data Source=""C:\Documents and Settings\Administrator\My
Documents\" & _

"FamilyPlusFriends.mdb"";Jet OLEDB:Engine
Type=5;Provider=""Microsoft.Jet.OLEDB.4.0" & _

""";Jet OLEDB:System database=;Jet
OLEDB:SFP=False;persist security
info=False;Ext" & _

"ended Properties=;Mode=Share Deny None;Jet
OLEDB:Encrypt Database=False;Jet
OLED" & _

"B:Create System Database=False;Jet OLEDB:Don't Copy Locale on
Compact=False;Jet " & _

"OLEDB:Compact Without Replica Repair=False;User ID=Admin;Jet OLEDB:Global
Bulk T" & _

"ransactions=1"

'open connection

con.Open()

'Initialise People

dgPeople.DataSource = tablePeople

cmd.CommandText = "SELECT ID,FirstName,LastName,DOB, [Mobile Fone],[Home
Phone],Email, Address1, Address2,Address3, Address4,Town, [Post Code],
County, Country,MiddleInnitial FROM(People)ORDER BY FirstName"

cmd.CommandType = CommandType.Text

cmd.Connection = con

daEvents.SelectCommand = cmd

daEvents.Fill(tablePeople)



'Initialise Events

dgEvents.DataSource = tableEvents

cmd.CommandType = CommandType.Text

cmd.CommandText = "SELECT * FROM Events WHERE id=?"

cmd.Connection = con

cmd.Parameters.Add("@ID", OleDbType.Integer).Value =
dgPeople.Item(dgPeople.CurrentRowIndex, 0)

daEvents.SelectCommand = cmd

daEvents.Fill(tableEvents)





'Close connection

con.Close()


.
 
Back
Top