In VB.net insert a row to a repeating table

S

SDecou

Could someone please respond and let me know how to do this? I am having
difficulty with selecting the table before actually adding the row. Thanks.
 
B

Ben Walters

Howdy,
You should be able to do this using the ExecuteAction method. Have a look in
the SDK for this it has some samples in there.
If youre still haveing trouble let me know and I'll put up some sample code

Cheers
Ben
 
S

SDecou

Thank you for responding Ben. I am at the end of my rope with this problem.
I searched around in the SDK and most of the sample code is written in C.
Could you please put some sample code together to do this. Here is what I
have so far. For some reason the code below is overwriting the data being
populated. I have the correct number of rows being inserted, but I only I
one row of data. Thank you in advance for taking a look at this for me.

Dim strsql As String
Dim lsysID As Integer
Dim SearchName As String
Dim MySelect As IXMLDOMNode
Dim myConnString = "Persist Security Info=False;Integrated
Security=SSPI;database=Overtime;server=clsqdb61;Connect Timeout=30"
Dim cn As New System.Data.SqlClient.SqlConnection(myConnString)
Dim FirstRow As Boolean
Dim thisnode As IXMLDOMNode =
thisXDocument.DOM.selectSingleNode("my:myFields/my:SearchQuery")

SearchName =
thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:SearchQuery/my:SearchText").text
strsql = "select * from vOTLogUsername where MyUsername = " &
"'" & SearchName & "'"

If cn.State = System.Data.ConnectionState.Closed Then
cn.Open()
End If
Dim cmd As New System.Data.SqlClient.SqlCommand(strsql, cn)
Dim reader As System.Data.SqlClient.SqlDataReader =
cmd.ExecuteReader
Dim i As Integer
If reader.HasRows Then
FirstRow = True
While reader.Read
If FirstRow = True Then
FirstRow = False
Else

thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:SearchQuery/my:SearchOvertimeID").text = reader("SysID")

thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:SearchQuery/my:SearchEmpID").text = reader("EmpID")

thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:SearchQuery/my:SearchStartDate").text = reader("StartDate")

thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:SearchQuery/my:SearchUsername").text = reader("MyUsername")

thisXDocument.View.ExecuteAction("xCollection::insert", "SearchQuery_58")
End If
End While
End If
reader.Close()
End Sub
 
B

Ben Walters

Your Problem is that you update the first row in the table then insert a new
blank row, you need to insert your blank row first then get a refernce to
the last field in the repeating table

thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:SearchQuery/my:SearchOvertimeID").text
= reader("SysID")
thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:SearchQuery/my:SearchEmpID").text= reader("EmpID") thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:SearchQuery/my:SearchStartDate").text = reader("StartDate") thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:SearchQuery/my:SearchUsername").text = reader("MyUsername")thisXDocument.View.ExecuteAction("xCollection::insert", "SearchQuery_58")the above Xpath queries will alwas return the first instance of the selectedfield that is found. This can be easily fixed by using the "last()"function. So your code would look like thisthisXDocument.View.ExecuteAction("xCollection::insert", "SearchQuery_58")thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:SearchQuery/my:SearchOvertimeID[last()]").text = reader("SysID")thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:SearchQuery/my:SearchEmpID[last()]").text = reader("EmpID")thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:SearchQuery/my:SearchStartDate[last()]").text = reader("StartDate")thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:SearchQuery/my:SearchUsername[last()]").text = reader("MyUsername")Another option would be to get a referece to the SearchQuery node and thenupdate the child nodes using the following codeDim mySearchQuery as IXMLDOMNode<Begin Loop>thisXDocument.View.ExecuteAction("xCollection::insert", "SearchQuery_58")mySearchQuery =thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:SearchQuery[last()]")mySearchQuery.selectSingleNode("/my:SearchOverTimeID").text =reader("SysID")mySearchQuery.selectSingleNode("/my:SearchEmpID[last()]").text =reader("EmpID")mySearchQuery.selectSingleNode("/my:SearchStartDate[last()]").text =reader("StartDate")mySearchQuery.selectSingleNode("/my:SearchUsername[last()]").text =reader("MyUsername")<End Loop>Hope this helpsBen"SDecou" <[email protected]> wrote in messageThank you for responding Ben. I am at the end of my rope with thisproblem.> I searched around in the SDK and most of the sample code is written in C.> Could you please put some sample code together to do this. Here is what I> have so far. For some reason the code below is overwriting the data being> populated. I have the correct number of rows being inserted, but I only I> one row of data. Thank you in advance for taking a look at this for me.>> Dim strsql As String> Dim lsysID As Integer> Dim SearchName As String> Dim MySelect As IXMLDOMNode> Dim myConnString = "Persist Security Info=False;Integrated> Security=SSPI;database=Overtime;server=clsqdb61;Connect Timeout=30"> Dim cn As New System.Data.SqlClient.SqlConnection(myConnString)> Dim FirstRow As Boolean> Dim thisnode As IXMLDOMNode => thisXDocument.DOM.selectSingleNode("my:myFields/my:SearchQuery")>> SearchName =>thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:SearchQuery/my:SearchText").text> strsql = "select * from vOTLogUsername where MyUsername = " &> "'" & SearchName & "'">> If cn.State = System.Data.ConnectionState.Closed Then> cn.Open()> End If> Dim cmd As New System.Data.SqlClient.SqlCommand(strsql, cn)> Dim reader As System.Data.SqlClient.SqlDataReader => cmd.ExecuteReader> Dim i As Integer> If reader.HasRows Then> FirstRow = True> While reader.Read> If FirstRow = True Then> FirstRow = False> Else>>thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:SearchQuery/my:SearchOvertimeID").text = reader("SysID")>>thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:SearchQuery/my:SearchEmpID").text = reader("EmpID")>>thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:SearchQuery/my:SearchStartDate").text = reader("StartDate")>>thisXDocument.DOM.selectSingleNode("/dfs:myFields/my:SearchQuery/my:SearchUsername").text = reader("MyUsername")>> thisXDocument.View.ExecuteAction("xCollection::insert", "SearchQuery_58")> End If> End While> End If> reader.Close()> End Sub>> "Ben Walters" wrote:>>> Howdy,>> You should be able to do this using the ExecuteAction method. Have a lookin>> the SDK for this it has some samples in there.>> If youre still haveing trouble let me know and I'll put up some samplecode>>>> Cheers>> Ben>>>> "SDecou" <[email protected]> wrote in message>> > Could someone please respond and let me know how to do this? I amhaving>> > difficulty with selecting the table before actually adding the row.>> > Thanks.>>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top