Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

ADO Datarelation inserts not working

Status
Not open for further replies.

phaseshift

IS-IT--Management
Dec 13, 2004
45
US
I have two tables with a PK FK relationship. In my code I have set a datarelation between the table but the addnew() is not working. Can anyone look over this and see if you spot a problem.

thanks

Dim conn As New SqlConnection

Dim daclient As New SqlDataAdapter
Dim dareferrals As New SqlDataAdapter

Dim ds As New DataSet

Dim cmdclient As New SqlCommand
Dim cmdreferrals As New SqlCommand


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

fileutilmod.getxmldata()
conn.ConnectionString = "Server= " & xmldataServerName & "; uid=" & xmldataUserName & " ; pwd=" & xmldataUserPass & "; database=" & xmldataDatabaseName & ";"

Try
'client info collection
cmdclient = conn.CreateCommand
cmdclient.CommandText = "Select * from tblclients"
daclient.SelectCommand = cmdclient
Dim cdclient As SqlCommandBuilder = New SqlCommandBuilder(daclient)
daclient.Fill(ds, "tblclients")

' referral info collection
cmdreferrals = conn.CreateCommand
cmdreferrals.CommandText = "Select * from tblreferrals"
dareferrals.SelectCommand = cmdreferrals
Dim cbreferrals As SqlCommandBuilder = New SqlCommandBuilder(dareferrals)
dareferrals.Fill(ds, "tblreferrals")


Dim relreferrals As New DataRelation _
("ds", ds.Tables("tblclients").Columns("clientid"), _
ds.Tables("tblreferrals").Columns("clientid"))
ds.Relations.Add(relreferrals)


'''Databinding info goes here

updateposition()

Catch ex As Exception
MsgBox(ex.Source & ": " & ex.Message)
End Try

End Sub

Private Sub btnnext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnnext.Click
Me.BindingContext(ds.Tables("tblclients")).Position += 1
Me.BindingContext(ds.Tables("tblreferrals")).Position += 1
updateposition()
End Sub

Private Sub btnprev_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnprev.Click
Me.BindingContext(ds.Tables("tblclients")).Position -= 1
Me.BindingContext(ds.Tables("tblreferrals")).Position -= 1
updateposition()
End Sub

Private Sub updateposition()
Me.lblposition.Text = ((Me.BindingContext(ds.Tables("tblclients")).Position + 1).ToString + _
" of " + Me.BindingContext(ds.Tables("tblclients")).Count.ToString)
End Sub

Private Sub btnupdate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnupdate.Click
Try
Me.BindingContext(ds.Tables("tblclients")).EndCurrentEdit()
daclient.Update(ds.Tables("tblclients"))

Me.BindingContext(ds.Tables("tblreferrals")).EndCurrentEdit()
dareferrals.Update(ds.Tables("tblreferrals"))


Catch ex As Exception
MsgBox(ex.Source & " " & ex.Message)
End Try
End Sub

Private Sub btnadd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnadd.Click
Try
Me.BindingContext(ds.Tables("tblclients")).EndCurrentEdit()
Me.BindingContext(ds.Tables("tblclients")).AddNew()

Me.BindingContext(ds.Tables("tblreferrals")).EndCurrentEdit()
Me.BindingContext(ds.Tables("tblreferrals")).AddNew()

updateposition()
Catch ex As Exception
MsgBox(ex.Source & " " & ex.Message)
End Try
End Sub
 
do you get an errormessage?

Christiaan Baes
Belgium

If you want to get an answer read this FAQ faq796-2540
There's no such thing as a winnable war - Sting
 
No there is not error it just isn't working. Through debuging I found that the addnew() and Update() work for the first table tblclients but nothing haves for the relational table.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top