Victor Charles
asked on
Help with MoveNext,MovePrevious,MoveFirst and MoveLast record featiures
Hello,
After I was able to successfully filter the data with the code in the related case, I tried to move to the next record with the code below but running into some problems.
I'm getting error:
'CmbRec' has a SelectedIndex which is invalid because it does not exist in the list of items.
Parameter name: value
on Line: CmbRec.SelectedIndex = Val(Subnode1.InnerText) - 1
Code:
Dim NodeCount As Integer = LinkStream.SelectNodes("Ro ot/Link"). Count
If (NodeNumber < NodeCount) Then
NodeNumber += 1 'Move to some next node
Dim node As XmlNode = LinkStream.SelectSingleNod e("Root/Li nk[" & NodeNumber & "]")
Dim Subnode1 As XmlNode = node.ChildNodes(0)
Dim Subnode2 As XmlNode = node.ChildNodes(1)
CmbRec.SelectedIndex = Val(Subnode1.InnerText) - 1
CmbDonor.SelectedIndex = Val(Subnode2.InnerText) - 1
btnPrev.Enabled = True
If (NodeNumber = NodeCount) Then
btnNext.Enabled = False
End If
Else
NodeNumber = 0 ' Reset count so start searching from zero (You can change strategy)
' btnNext.Enabled = False
End If
Can you please help me solve this issue.
Thanks,
Victor
After I was able to successfully filter the data with the code in the related case, I tried to move to the next record with the code below but running into some problems.
I'm getting error:
'CmbRec' has a SelectedIndex which is invalid because it does not exist in the list of items.
Parameter name: value
on Line: CmbRec.SelectedIndex = Val(Subnode1.InnerText) - 1
Code:
Dim NodeCount As Integer = LinkStream.SelectNodes("Ro
If (NodeNumber < NodeCount) Then
NodeNumber += 1 'Move to some next node
Dim node As XmlNode = LinkStream.SelectSingleNod
Dim Subnode1 As XmlNode = node.ChildNodes(0)
Dim Subnode2 As XmlNode = node.ChildNodes(1)
CmbRec.SelectedIndex = Val(Subnode1.InnerText) - 1
CmbDonor.SelectedIndex = Val(Subnode2.InnerText) - 1
btnPrev.Enabled = True
If (NodeNumber = NodeCount) Then
btnNext.Enabled = False
End If
Else
NodeNumber = 0 ' Reset count so start searching from zero (You can change strategy)
' btnNext.Enabled = False
End If
Can you please help me solve this issue.
Thanks,
Victor
ASKER
Hello,
I'm using the code below to move to the next record but for some reason, after I move to the 4th record, it doesn't work. For example, I hard coded the value 4 in my code for ReceiverID, which has 6 records in Link.xml, Therefore when I press the Next button I was expecting to Move Next all the way to record number 6, but as mentioned after record number 4, it doesn't work, after a few click it jumps back to record number3. Below are my code and xml files, can you please help me figure out why Move Next button doesn't work after the 4th record?
CodeA: (Load comboboxes where ReceiverID = 4 in link.xml)
lnk.Load(Application.Start upPath & "/link.xml") 'My.Resources.Link)
Dim RecName As XmlNodeList = RecStream.SelectNodes("Roo t/Receiver ")
Dim DonorName As XmlNodeList = DonorStream.SelectNodes("R oot/Donor" )
Dim donorlst As New DataTable()
donorlst.Columns.Add("ID")
donorlst.Columns.Add("Name ")
Dim reclst As New DataTable
reclst.Columns.Add("ID")
reclst.Columns.Add("Name")
Dim x As Integer
x = 4
For Each xnLink As Xml.XmlNode In lnk.SelectNodes("/Root/Lin k[Receiver ID='" & x & "']")
' For Each n As XmlNode In lnk
Dim rID As Integer = Val(xnLink.ChildNodes(1).I nnerText)
Dim dID As Integer = Val(xnLink.ChildNodes(2).I nnerText)
For Each node As XmlNode In RecName
If node.ChildNodes(0).InnerTe xt = rID.ToString Then
' reclst.Rows.Add(New Object() {rID, node.ChildNodes(1).InnerTe xt})
reclst.Rows.Add(New Object() {rID, node.ChildNodes(0).InnerTe xt})
End If
Next
For Each node As XmlNode In DonorName
If node.ChildNodes(0).InnerTe xt = dID.ToString Then
'donorlst.Rows.Add(New Object() {node.ChildNodes(0).InnerT ext, node.ChildNodes(1).InnerTe xt})
donorlst.Rows.Add(New Object() {dID, node.ChildNodes(1).InnerTe xt})
End If
Next
Next
cc = donorlst.Rows.Count
CmbDonor.DataSource = donorlst
CmbDonor.DisplayMember = "Name"
CmbDonor.ValueMember = "ID"
CmbRec.DataSource = reclst
CmbRec.DisplayMember = "Name"
CmbRec.ValueMember = "ID"
CoeB: Move Next Button
MsgBox(lnk.SelectNodes("Ro ot/Link"). Count)
Dim NodeCount As Integer = lnk.SelectNodes("Root/Link ").Count
If (NodeNumber < cc) Then
NodeNumber += 1
Dim node As XmlNode = lnk.SelectSingleNode("Root /Link[" & NodeNumber & "]")
Dim Subnode1 As XmlNode = node.ChildNodes(1)
Dim Subnode2 As XmlNode = node.ChildNodes(2)
CmbRec.SelectedIndex = Val(Subnode1.InnerText) - 1
CmbDonor.SelectedIndex = Val(Subnode2.InnerText) - 1
Else
NodeNumber = 0 ' Reset count so start searching from zero (You can change strategy)
End If
Link.xml (Last 6 records include ReceiverID = 4)
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Root>
<Link>
<LinkID>1</LinkID>
<ReceiverID>1</ReceiverID>
<DonorID>2</DonorID></Link >
<Link>
<LinkID>2</LinkID>
<ReceiverID>1</ReceiverID>
<DonorID>3</DonorID>
</Link>
<Link>
<LinkID>3</LinkID>
<ReceiverID>1</ReceiverID>
<DonorID>4</DonorID>
</Link>
<Link>
<LinkID>4</LinkID>
<ReceiverID>2</ReceiverID>
<DonorID>4</DonorID>
</Link>
<Link>
<LinkID>5</LinkID>
<ReceiverID>1</ReceiverID>
<DonorID>2</DonorID>
</Link>
<Link>
<LinkID>6</LinkID>
<ReceiverID>2</ReceiverID>
<DonorID>2</DonorID>
</Link>
<Link>
<LinkID>7</LinkID>
<ReceiverID>4</ReceiverID>
<DonorID>1</DonorID>
</Link>
<Link>
<LinkID>8</LinkID>
<ReceiverID>4</ReceiverID>
<DonorID>2</DonorID>
</Link>
<Link>
<LinkID>9</LinkID>
<ReceiverID>4</ReceiverID>
<DonorID>3</DonorID>
</Link>
<Link>
<LinkID>10</LinkID>
<ReceiverID>4</ReceiverID>
<DonorID>4</DonorID>
</Link>
<Link>
<LinkID>11</LinkID>
<ReceiverID>4</ReceiverID>
<DonorID>5</DonorID>
</Link>
<Link>
<LinkID>12</LinkID>
<ReceiverID>4</ReceiverID>
<DonorID>6</DonorID>
</Link>
</Root>
I'm using the code below to move to the next record but for some reason, after I move to the 4th record, it doesn't work. For example, I hard coded the value 4 in my code for ReceiverID, which has 6 records in Link.xml, Therefore when I press the Next button I was expecting to Move Next all the way to record number 6, but as mentioned after record number 4, it doesn't work, after a few click it jumps back to record number3. Below are my code and xml files, can you please help me figure out why Move Next button doesn't work after the 4th record?
CodeA: (Load comboboxes where ReceiverID = 4 in link.xml)
lnk.Load(Application.Start
Dim RecName As XmlNodeList = RecStream.SelectNodes("Roo
Dim DonorName As XmlNodeList = DonorStream.SelectNodes("R
Dim donorlst As New DataTable()
donorlst.Columns.Add("ID")
donorlst.Columns.Add("Name
Dim reclst As New DataTable
reclst.Columns.Add("ID")
reclst.Columns.Add("Name")
Dim x As Integer
x = 4
For Each xnLink As Xml.XmlNode In lnk.SelectNodes("/Root/Lin
' For Each n As XmlNode In lnk
Dim rID As Integer = Val(xnLink.ChildNodes(1).I
Dim dID As Integer = Val(xnLink.ChildNodes(2).I
For Each node As XmlNode In RecName
If node.ChildNodes(0).InnerTe
' reclst.Rows.Add(New Object() {rID, node.ChildNodes(1).InnerTe
reclst.Rows.Add(New Object() {rID, node.ChildNodes(0).InnerTe
End If
Next
For Each node As XmlNode In DonorName
If node.ChildNodes(0).InnerTe
'donorlst.Rows.Add(New Object() {node.ChildNodes(0).InnerT
donorlst.Rows.Add(New Object() {dID, node.ChildNodes(1).InnerTe
End If
Next
Next
cc = donorlst.Rows.Count
CmbDonor.DataSource = donorlst
CmbDonor.DisplayMember = "Name"
CmbDonor.ValueMember = "ID"
CmbRec.DataSource = reclst
CmbRec.DisplayMember = "Name"
CmbRec.ValueMember = "ID"
CoeB: Move Next Button
MsgBox(lnk.SelectNodes("Ro
Dim NodeCount As Integer = lnk.SelectNodes("Root/Link
If (NodeNumber < cc) Then
NodeNumber += 1
Dim node As XmlNode = lnk.SelectSingleNode("Root
Dim Subnode1 As XmlNode = node.ChildNodes(1)
Dim Subnode2 As XmlNode = node.ChildNodes(2)
CmbRec.SelectedIndex = Val(Subnode1.InnerText) - 1
CmbDonor.SelectedIndex = Val(Subnode2.InnerText) - 1
Else
NodeNumber = 0 ' Reset count so start searching from zero (You can change strategy)
End If
Link.xml (Last 6 records include ReceiverID = 4)
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<Root>
<Link>
<LinkID>1</LinkID>
<ReceiverID>1</ReceiverID>
<DonorID>2</DonorID></Link
<Link>
<LinkID>2</LinkID>
<ReceiverID>1</ReceiverID>
<DonorID>3</DonorID>
</Link>
<Link>
<LinkID>3</LinkID>
<ReceiverID>1</ReceiverID>
<DonorID>4</DonorID>
</Link>
<Link>
<LinkID>4</LinkID>
<ReceiverID>2</ReceiverID>
<DonorID>4</DonorID>
</Link>
<Link>
<LinkID>5</LinkID>
<ReceiverID>1</ReceiverID>
<DonorID>2</DonorID>
</Link>
<Link>
<LinkID>6</LinkID>
<ReceiverID>2</ReceiverID>
<DonorID>2</DonorID>
</Link>
<Link>
<LinkID>7</LinkID>
<ReceiverID>4</ReceiverID>
<DonorID>1</DonorID>
</Link>
<Link>
<LinkID>8</LinkID>
<ReceiverID>4</ReceiverID>
<DonorID>2</DonorID>
</Link>
<Link>
<LinkID>9</LinkID>
<ReceiverID>4</ReceiverID>
<DonorID>3</DonorID>
</Link>
<Link>
<LinkID>10</LinkID>
<ReceiverID>4</ReceiverID>
<DonorID>4</DonorID>
</Link>
<Link>
<LinkID>11</LinkID>
<ReceiverID>4</ReceiverID>
<DonorID>5</DonorID>
</Link>
<Link>
<LinkID>12</LinkID>
<ReceiverID>4</ReceiverID>
<DonorID>6</DonorID>
</Link>
</Root>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi,
Can you please send me an example using my project information, I still do not
see how this approach will help me with moving to Next or previous records.
Thanks,
Victor
Can you please send me an example using my project information, I still do not
see how this approach will help me with moving to Next or previous records.
Thanks,
Victor
ASKER
Hello,
I'm trying the sample project to better understand how LinQToXML works, but I'm getting error:
Error: The name 'Data' does not exist in the current context
On Line: Data.DAL.Save(customer);
How do I fix this error?
Code:
using System;
using System.Collections.Generic ;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
namespace LINQXMLCSHARP
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
public class Customer
{
public int ID { get; set; }
public string Forename { get; set; }
public string Surname { get; set; }
public string DOB { get; set; }
public string Location { get; set; }
}
public static Customer GetCustomer(int customerID)
{
XDocument data = XDocument.Load(HttpContext .Current.S erver.MapP ath("~/Dat a/Customer s.xml"));
return (from c in data.Descendants("Customer ")
where c.Attribute("ID").Value.Eq uals(custo merID.ToSt ring())
select new Customer()
{
ID = Convert.ToInt32(c.Attribut e("ID").Va lue),
Forename = c.Element("Forename").Valu e,
Surname = c.Element("Surname").Value ,
DOB = c.Element("DOB").Value,
Location = c.Element("Location").Valu e
}).FirstOrDefault();
}
public static List<Customer> GetCustomers()
{
XDocument data = XDocument.Load(HttpContext .Current.S erver.MapP ath("~/Dat a/Customer s.xml"));
return (from c in data.Descendants("Customer ")
orderby c.Attribute("Surname")
select new Customer()
{
ID = Convert.ToInt32(c.Attribut e("ID").Va lue),
Forename = c.Element("Forename").Valu e,
Surname = c.Element("Surname").Value ,
DOB = c.Element("DOB").Value,
Location = c.Element("Location").Valu e
}).ToList();
}
public static void Save(Customer customer)
{
XDocument data = XDocument.Load(HttpContext .Current.S erver.MapP ath("~/Dat a/Customer s.xml"));
if (customer.ID > 0)
{
XElement customerElement = data.Descendants("Customer ").Where(c => c.Attribute("ID").Value.Eq uals(custo mer.ID.ToS tring())). FirstOrDef ault();
if (customerElement != null)
{
customerElement.SetElement Value("For ename", customer.Forename);
customerElement.SetElement Value("Sur name", customer.Surname);
customerElement.SetElement Value("DOB ", customer.DOB);
customerElement.SetElement Value("Loc ation", customer.Location);
data.Save(HttpContext.Curr ent.Server .MapPath(" ~/Data/Cus tomers.xml "));
}
}
else
{
XElement newCustomer = new XElement("Customer",
new XElement("Forename", customer.Forename),
new XElement("Surname", customer.Surname),
new XElement("DOB", customer.DOB),
new XElement("Location", customer.Location)
);
newCustomer.SetAttributeVa lue("ID", GetNextAvailableID());
data.Element("Customers"). Add(newCus tomer);
data.Save(HttpContext.Curr ent.Server .MapPath(" ~/Data/Cus tomers.xml "));
}
}
private static int GetNextAvailableID()
{
XDocument data = XDocument.Load(HttpContext .Current.S erver.MapP ath("~/Dat a/Customer s.xml"));
return Convert.ToInt32(
(from c in data.Descendants("Customer ")
orderby Convert.ToInt32(c.Attribut e("ID").Va lue) descending
select c.Attribute("ID").Value).F irstOrDefa ult()
) + 1;
}
public static void Delete(Customer customer)
{
XDocument data = XDocument.Load(HttpContext .Current.S erver.MapP ath("~/Dat a/Customer s.xml"));
XElement customerElement = data.Descendants("Customer ").Where(c => c.Attribute("ID").Value.Eq uals(custo mer.ID.ToS tring())). FirstOrDef ault();
if (customerElement != null)
{
customerElement.Remove();
data.Save(HttpContext.Curr ent.Server .MapPath(" ~/Data/Cus tomers.xml "));
}
}
protected void btnAddCustomer_Click(objec t sender, EventArgs e)
{
Customer customer = new Customer()
{
Forename = txtForename.Text.Trim(),
Surname = txtSurname.Text.Trim(),
DOB = txtDOB.Text.Trim(),
Location = txtLocation.Text.Trim()
};
Data.DAL.Save(customer); ******************Error Line********************** **
ClearForm();
gvCustomers.DataBind();
txtForename.Focus();
}
private void ClearForm()
{
txtForename.Text = string.Empty;
txtSurname.Text = string.Empty;
txtDOB.Text = string.Empty;
txtLocation.Text = string.Empty;
}
}
}
I'm trying the sample project to better understand how LinQToXML works, but I'm getting error:
Error: The name 'Data' does not exist in the current context
On Line: Data.DAL.Save(customer);
How do I fix this error?
Code:
using System;
using System.Collections.Generic
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;
namespace LINQXMLCSHARP
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
}
public class Customer
{
public int ID { get; set; }
public string Forename { get; set; }
public string Surname { get; set; }
public string DOB { get; set; }
public string Location { get; set; }
}
public static Customer GetCustomer(int customerID)
{
XDocument data = XDocument.Load(HttpContext
return (from c in data.Descendants("Customer
where c.Attribute("ID").Value.Eq
select new Customer()
{
ID = Convert.ToInt32(c.Attribut
Forename = c.Element("Forename").Valu
Surname = c.Element("Surname").Value
DOB = c.Element("DOB").Value,
Location = c.Element("Location").Valu
}).FirstOrDefault();
}
public static List<Customer> GetCustomers()
{
XDocument data = XDocument.Load(HttpContext
return (from c in data.Descendants("Customer
orderby c.Attribute("Surname")
select new Customer()
{
ID = Convert.ToInt32(c.Attribut
Forename = c.Element("Forename").Valu
Surname = c.Element("Surname").Value
DOB = c.Element("DOB").Value,
Location = c.Element("Location").Valu
}).ToList();
}
public static void Save(Customer customer)
{
XDocument data = XDocument.Load(HttpContext
if (customer.ID > 0)
{
XElement customerElement = data.Descendants("Customer
if (customerElement != null)
{
customerElement.SetElement
customerElement.SetElement
customerElement.SetElement
customerElement.SetElement
data.Save(HttpContext.Curr
}
}
else
{
XElement newCustomer = new XElement("Customer",
new XElement("Forename", customer.Forename),
new XElement("Surname", customer.Surname),
new XElement("DOB", customer.DOB),
new XElement("Location", customer.Location)
);
newCustomer.SetAttributeVa
data.Element("Customers").
data.Save(HttpContext.Curr
}
}
private static int GetNextAvailableID()
{
XDocument data = XDocument.Load(HttpContext
return Convert.ToInt32(
(from c in data.Descendants("Customer
orderby Convert.ToInt32(c.Attribut
select c.Attribute("ID").Value).F
) + 1;
}
public static void Delete(Customer customer)
{
XDocument data = XDocument.Load(HttpContext
XElement customerElement = data.Descendants("Customer
if (customerElement != null)
{
customerElement.Remove();
data.Save(HttpContext.Curr
}
}
protected void btnAddCustomer_Click(objec
{
Customer customer = new Customer()
{
Forename = txtForename.Text.Trim(),
Surname = txtSurname.Text.Trim(),
DOB = txtDOB.Text.Trim(),
Location = txtLocation.Text.Trim()
};
Data.DAL.Save(customer); ******************Error Line**********************
ClearForm();
gvCustomers.DataBind();
txtForename.Focus();
}
private void ClearForm()
{
txtForename.Text = string.Empty;
txtSurname.Text = string.Empty;
txtDOB.Text = string.Empty;
txtLocation.Text = string.Empty;
}
}
}
ASKER
I removed Data.DAL.Save(customer); from the code and ran the project and received the following error:
The type specified in the TypeName property of ObjectDataSource 'odsCustomers' could not be found.
I'm not sure if it's cause I removed that line or a totally separate issue.
How do I create the ObjectDataSource?
Thanks,
Victor
The type specified in the TypeName property of ObjectDataSource 'odsCustomers' could not be found.
I'm not sure if it's cause I removed that line or a totally separate issue.
How do I create the ObjectDataSource?
Thanks,
Victor
ASKER
Hi,
Going back to my initial post, I figured out the reason the MoveNext button doesn't work properly is because I am looping through the original Link.xml fikle insatead of the one that was filtered. Is there a way to create a temp Link.xml just for thet session and pass it the values from the filtered search to use for the Next button. I admit it sounds complicated but would like to get tt work anyway possible and try to improve it at a later stage.
MoveNext Code:
Dim NodeCount As Integer = lnk.SelectNodes("Root/Link ").Count
NodeNumber += 1
Dim node As XmlNode = lnk.SelectSingleNode("Root /Link[" & NodeNumber & "]")
Dim Subnode1 As XmlNode = node.ChildNodes(1)
Dim Subnode2 As XmlNode = node.ChildNodes(2)
MsgBox(Val(Subnode1.InnerT ext))
MsgBox(Val(Subnode2.InnerT ext))
CmbRec.SelectedIndex = Val(Subnode1.InnerText) - 1
CmbDonor.SelectedIndex = Val(Subnode2.InnerText) - 1
As mentioned code is going using original Link.xml file instead of Lnk created when filtered data with code below:
Dim RecName As XmlNodeList = RecStream.SelectNodes("Roo t/Receiver ")
Dim DonorName As XmlNodeList = DonorStream.SelectNodes("R oot/Donor" )
Dim donorlst As New DataTable()
donorlst.Columns.Add("ID")
donorlst.Columns.Add("Name ")
Dim reclst As New DataTable
reclst.Columns.Add("ID")
reclst.Columns.Add("Name")
Dim x As Integer
x = 5
For Each xnLink As Xml.XmlNode In lnk.SelectNodes("/Root/Lin k[Receiver ID='" & x & "']")
' For Each n As XmlNode In lnk
Dim rID As Integer = Val(xnLink.ChildNodes(1).I nnerText)
Dim dID As Integer = Val(xnLink.ChildNodes(2).I nnerText)
'*****
'How do I add code to put rID and dID values in a Temp Link file for each session?
'*******
For Each node As XmlNode In RecName
If node.ChildNodes(0).InnerTe xt = rID.ToString Then
reclst.Rows.Add(New Object() {rID, node.ChildNodes(1).InnerTe xt})
End If
Next
For Each node As XmlNode In DonorName
If node.ChildNodes(0).InnerTe xt = dID.ToString Then
'donorlst.Rows.Add(New Object() {node.ChildNodes(0).InnerT ext, node.ChildNodes(1).InnerTe xt})
donorlst.Rows.Add(New Object() {dID, node.ChildNodes(1).InnerTe xt})
End If
Next
Next
cc = donorlst.Rows.Count
CmbDonor.DataSource = donorlst
CmbDonor.DisplayMember = "Name"
CmbDonor.ValueMember = "ID"
CmbRec.DataSource = reclst
CmbRec.DisplayMember = "Name"
CmbRec.ValueMember = "ID"
Going back to my initial post, I figured out the reason the MoveNext button doesn't work properly is because I am looping through the original Link.xml fikle insatead of the one that was filtered. Is there a way to create a temp Link.xml just for thet session and pass it the values from the filtered search to use for the Next button. I admit it sounds complicated but would like to get tt work anyway possible and try to improve it at a later stage.
MoveNext Code:
Dim NodeCount As Integer = lnk.SelectNodes("Root/Link
NodeNumber += 1
Dim node As XmlNode = lnk.SelectSingleNode("Root
Dim Subnode1 As XmlNode = node.ChildNodes(1)
Dim Subnode2 As XmlNode = node.ChildNodes(2)
MsgBox(Val(Subnode1.InnerT
MsgBox(Val(Subnode2.InnerT
CmbRec.SelectedIndex = Val(Subnode1.InnerText) - 1
CmbDonor.SelectedIndex = Val(Subnode2.InnerText) - 1
As mentioned code is going using original Link.xml file instead of Lnk created when filtered data with code below:
Dim RecName As XmlNodeList = RecStream.SelectNodes("Roo
Dim DonorName As XmlNodeList = DonorStream.SelectNodes("R
Dim donorlst As New DataTable()
donorlst.Columns.Add("ID")
donorlst.Columns.Add("Name
Dim reclst As New DataTable
reclst.Columns.Add("ID")
reclst.Columns.Add("Name")
Dim x As Integer
x = 5
For Each xnLink As Xml.XmlNode In lnk.SelectNodes("/Root/Lin
' For Each n As XmlNode In lnk
Dim rID As Integer = Val(xnLink.ChildNodes(1).I
Dim dID As Integer = Val(xnLink.ChildNodes(2).I
'*****
'How do I add code to put rID and dID values in a Temp Link file for each session?
'*******
For Each node As XmlNode In RecName
If node.ChildNodes(0).InnerTe
reclst.Rows.Add(New Object() {rID, node.ChildNodes(1).InnerTe
End If
Next
For Each node As XmlNode In DonorName
If node.ChildNodes(0).InnerTe
'donorlst.Rows.Add(New Object() {node.ChildNodes(0).InnerT
donorlst.Rows.Add(New Object() {dID, node.ChildNodes(1).InnerTe
End If
Next
Next
cc = donorlst.Rows.Count
CmbDonor.DataSource = donorlst
CmbDonor.DisplayMember = "Name"
CmbDonor.ValueMember = "ID"
CmbRec.DataSource = reclst
CmbRec.DisplayMember = "Name"
CmbRec.ValueMember = "ID"
ASKER
Hi,
I managed to created a LinkTemp.xml file with the values that meet my search criteria (i.e. x = 5), using the codeA below and was able to Move Next to the correct records. Now when the users select one of the records and makes a change in the Receiver combobox for example, what code would replace the old ID with the New ID of the data selected to the original Link.xml file? I started working with CodeB but couldn't figure it out, instaed of changing the values, I'm getting a new record with the selected Values IDs.
CodeA:
Dim xml As String = lnk.InnerXml
Dim newline As String = Environment.NewLine
Dim replacement As String = "<Link><ReceiverID>" & rID & "</ReceiverID><DonorID>" & dID & "</DonorID></Link>"
lnk.InnerXml = lnk.InnerXml.Replace("</Ro ot>", "") & replacement & "</Root>"
lnk.Save(Application.Start upPath & "/LinkTemp.xml")
CodeB:
If (NodeNumber = 0) Then
NodeNumber = 1
End If
Dim link As XmlNode = LinkStream.SelectSingleNod e("Root/Li nk[" & NodeNumber & "]")
Dim newnode As XmlNode = link.Clone '(True)
newnode.InnerXml = "<ReceiverID>" & CmbRec.SelectedValue & "</ReceiverID>" & "<DonorID>" & CmbDonor.SelectedValue & "</DonorID>"
link.InnerXml = newnode.InnerXml
LinkStream.Save(Applicatio n.StartupP ath & "/Link.xml")
I managed to created a LinkTemp.xml file with the values that meet my search criteria (i.e. x = 5), using the codeA below and was able to Move Next to the correct records. Now when the users select one of the records and makes a change in the Receiver combobox for example, what code would replace the old ID with the New ID of the data selected to the original Link.xml file? I started working with CodeB but couldn't figure it out, instaed of changing the values, I'm getting a new record with the selected Values IDs.
CodeA:
Dim xml As String = lnk.InnerXml
Dim newline As String = Environment.NewLine
Dim replacement As String = "<Link><ReceiverID>" & rID & "</ReceiverID><DonorID>" & dID & "</DonorID></Link>"
lnk.InnerXml = lnk.InnerXml.Replace("</Ro
lnk.Save(Application.Start
CodeB:
If (NodeNumber = 0) Then
NodeNumber = 1
End If
Dim link As XmlNode = LinkStream.SelectSingleNod
Dim newnode As XmlNode = link.Clone '(True)
newnode.InnerXml = "<ReceiverID>" & CmbRec.SelectedValue & "</ReceiverID>" & "<DonorID>" & CmbDonor.SelectedValue & "</DonorID>"
link.InnerXml = newnode.InnerXml
LinkStream.Save(Applicatio
You are the best one to decide what you want to do, so my "job" is to only suggest and guide. I don't quite understand your problem space, and your question either. A "temp" file should be just keeping a different variable reference to the information. Is it the filtered part that is causing you difficulty?
ASKER
I prefer you method but it was in C# and I couldn't get the sample to work to help me understand the code in the sample project, as mentioned I'm getting:
Error: The name 'Data' does not exist in the current context
On Line: Data.DAL.Save(customer);
Therefore I decide to see if I can work more on my old code to try to make it work,
Basically what I need to do is move the Next/Previous record after I obtain my results from codeA below.
CodeA: (Load comboboxes where ReceiverID = 4 in link.xml)
lnk.Load(Application.Start upPath & "/link.xml") 'My.Resources.Link)
Dim RecName As XmlNodeList = RecStream.SelectNodes("Roo t/Receiver ")
Dim DonorName As XmlNodeList = DonorStream.SelectNodes("R oot/Donor" )
Dim donorlst As New DataTable()
donorlst.Columns.Add("ID")
donorlst.Columns.Add("Name ")
Dim reclst As New DataTable
reclst.Columns.Add("ID")
reclst.Columns.Add("Name")
Dim x As Integer
x = 4
For Each xnLink As Xml.XmlNode In lnk.SelectNodes("/Root/Lin k[Receiver ID='" & x & "']")
' For Each n As XmlNode In lnk
Dim rID As Integer = Val(xnLink.ChildNodes(1).I nnerText)
Dim dID As Integer = Val(xnLink.ChildNodes(2).I nnerText)
For Each node As XmlNode In RecName
If node.ChildNodes(0).InnerTe xt = rID.ToString Then
' reclst.Rows.Add(New Object() {rID, node.ChildNodes(1).InnerTe xt})
reclst.Rows.Add(New Object() {rID, node.ChildNodes(0).InnerTe xt})
End If
Next
For Each node As XmlNode In DonorName
If node.ChildNodes(0).InnerTe xt = dID.ToString Then
'donorlst.Rows.Add(New Object() {node.ChildNodes(0).InnerT ext, node.ChildNodes(1).InnerTe xt})
donorlst.Rows.Add(New Object() {dID, node.ChildNodes(1).InnerTe xt})
End If
Next
Next
cc = donorlst.Rows.Count
CmbDonor.DataSource = donorlst
CmbDonor.DisplayMember = "Name"
CmbDonor.ValueMember = "ID"
CmbRec.DataSource = reclst
CmbRec.DisplayMember = "Name"
CmbRec.ValueMember = "ID"
After achieving to Move to Next?Previous records, I need to be able to Modify the data in a particular record or delete the record. My main issue is with the code to move to Next/Previous records, if possible I would like to keep the approach in CodeA to filter the record, but I'm willing to change that approach if I can find a better one that would help me achieve all my requirements.
Victor
Error: The name 'Data' does not exist in the current context
On Line: Data.DAL.Save(customer);
Therefore I decide to see if I can work more on my old code to try to make it work,
Basically what I need to do is move the Next/Previous record after I obtain my results from codeA below.
CodeA: (Load comboboxes where ReceiverID = 4 in link.xml)
lnk.Load(Application.Start
Dim RecName As XmlNodeList = RecStream.SelectNodes("Roo
Dim DonorName As XmlNodeList = DonorStream.SelectNodes("R
Dim donorlst As New DataTable()
donorlst.Columns.Add("ID")
donorlst.Columns.Add("Name
Dim reclst As New DataTable
reclst.Columns.Add("ID")
reclst.Columns.Add("Name")
Dim x As Integer
x = 4
For Each xnLink As Xml.XmlNode In lnk.SelectNodes("/Root/Lin
' For Each n As XmlNode In lnk
Dim rID As Integer = Val(xnLink.ChildNodes(1).I
Dim dID As Integer = Val(xnLink.ChildNodes(2).I
For Each node As XmlNode In RecName
If node.ChildNodes(0).InnerTe
' reclst.Rows.Add(New Object() {rID, node.ChildNodes(1).InnerTe
reclst.Rows.Add(New Object() {rID, node.ChildNodes(0).InnerTe
End If
Next
For Each node As XmlNode In DonorName
If node.ChildNodes(0).InnerTe
'donorlst.Rows.Add(New Object() {node.ChildNodes(0).InnerT
donorlst.Rows.Add(New Object() {dID, node.ChildNodes(1).InnerTe
End If
Next
Next
cc = donorlst.Rows.Count
CmbDonor.DataSource = donorlst
CmbDonor.DisplayMember = "Name"
CmbDonor.ValueMember = "ID"
CmbRec.DataSource = reclst
CmbRec.DisplayMember = "Name"
CmbRec.ValueMember = "ID"
After achieving to Move to Next?Previous records, I need to be able to Modify the data in a particular record or delete the record. My main issue is with the code to move to Next/Previous records, if possible I would like to keep the approach in CodeA to filter the record, but I'm willing to change that approach if I can find a better one that would help me achieve all my requirements.
Victor
ASKER
Hello,
The code below finds all the records that meets a search criteria and displays the data in two web controls. Is there a way to modify the For Each command to only find one record for each click of the button (for example Find next or Find Previous) . I believe this might be a solution for moving to Next or Previous records. I think the best approach would be to keep the existing code and display the data when Moving to Next or Previous records by moving through the tables, but I can't figure out how to do that also.
For Each xnLink As Xml.XmlNode In xdLink.SelectNodes("/Root/ Link[Recei verID='" & C1Country.SelectedItem.Val ue & "']")
' Extract the ReceiverID and DonorID values from the current node
Dim ReceiverID As String
Dim DonorID As String
ReceiverID = xnLink.SelectSingleNode("R eceiverID" ).InnerTex t
DonorID = xnLink.SelectSingleNode("D onorID").I nnerText
' Perform another similar search based upon the Donor XML file
For Each xnDonor As Xml.XmlNode In xdDonor.SelectNodes("/Root /Donor[Don orID='" & DonorID & "']")
' Extract the DonorID and Name values from the current node
Dim DonorID2 As String
Dim Name As String
DonorID2 = xnDonor.SelectSingleNode(" DonorID"). InnerText
Name = xnDonor.SelectSingleNode(" Name").Inn erText
dtDonor.Rows.Add({DonorID2 , Name})
Next
' Perform yet another practically identical search on the Receiver XML file
For Each xnReceiver As Xml.XmlNode In xdReceiver.SelectNodes("/R oot/Receiv er[Receive rID='" & ReceiverID & "']")
' Extract the ReceiverID and Name values from the current node
Dim ReceiverID2 As String
Dim Name As String
ReceiverID2 = xnReceiver.SelectSingleNod e("Receive rID").Inne rText
Name = xnReceiver.SelectSingleNod e("Name"). InnerText
dtReceiver.Rows.Add({Recei verID2, Name})
Next
Next
End If
Code: Displays
Receiver_Control (However users will only see first row, code will be implement so when users click on combobo lit of all countries will be listed to give them a choice to update the data)
BEL
CAN
DEU
ESP
Donor Control
USA
BEL
GBR
CAN
I need Press Next button and see
Receiver
CAN
Donor
BEL
Press Next button and see:
Receiver
DEU
Donor
GBR
Press Next button and see:
Receiver
ESP
Donor
CAN
and when Users press Previous button they will see previois record:
Receiver
DEU
Donor
GBR
The code below finds all the records that meets a search criteria and displays the data in two web controls. Is there a way to modify the For Each command to only find one record for each click of the button (for example Find next or Find Previous) . I believe this might be a solution for moving to Next or Previous records. I think the best approach would be to keep the existing code and display the data when Moving to Next or Previous records by moving through the tables, but I can't figure out how to do that also.
For Each xnLink As Xml.XmlNode In xdLink.SelectNodes("/Root/
' Extract the ReceiverID and DonorID values from the current node
Dim ReceiverID As String
Dim DonorID As String
ReceiverID = xnLink.SelectSingleNode("R
DonorID = xnLink.SelectSingleNode("D
' Perform another similar search based upon the Donor XML file
For Each xnDonor As Xml.XmlNode In xdDonor.SelectNodes("/Root
' Extract the DonorID and Name values from the current node
Dim DonorID2 As String
Dim Name As String
DonorID2 = xnDonor.SelectSingleNode("
Name = xnDonor.SelectSingleNode("
dtDonor.Rows.Add({DonorID2
Next
' Perform yet another practically identical search on the Receiver XML file
For Each xnReceiver As Xml.XmlNode In xdReceiver.SelectNodes("/R
' Extract the ReceiverID and Name values from the current node
Dim ReceiverID2 As String
Dim Name As String
ReceiverID2 = xnReceiver.SelectSingleNod
Name = xnReceiver.SelectSingleNod
dtReceiver.Rows.Add({Recei
Next
Next
End If
Code: Displays
Receiver_Control (However users will only see first row, code will be implement so when users click on combobo lit of all countries will be listed to give them a choice to update the data)
BEL
CAN
DEU
ESP
Donor Control
USA
BEL
GBR
CAN
I need Press Next button and see
Receiver
CAN
Donor
BEL
Press Next button and see:
Receiver
DEU
Donor
GBR
Press Next button and see:
Receiver
ESP
Donor
CAN
and when Users press Previous button they will see previois record:
Receiver
DEU
Donor
GBR
ASKER
Hi again,
Is there a way to open dtReciver and dtDonor tables and move through their records created from the previous post, using the Move Next/Previous buttons while displaying the data in the comboboxes?
Thanks,
Victor
Is there a way to open dtReciver and dtDonor tables and move through their records created from the previous post, using the Move Next/Previous buttons while displaying the data in the comboboxes?
Thanks,
Victor
ASKER
Hello again,
After binding the tables to CmbRec and CmbDonor with the syntax below, I can find a property to move to next or previous records, do you know if such properties exiist or another way to move to next or previous records?,
CmbRec.DataSource = dtReceiver
CmbRec.DataTextField = "Name"
CmbRec.DataValueField = "ReceiverID"
CmbRec.DataBind()
CmbDonor.DataSource = dtDonor
CmbDonor.DataTextField = "Name"
CmbDonor.DataValueField = "DonorID"
CmbDonor.DataBind()
After binding the tables to CmbRec and CmbDonor with the syntax below, I can find a property to move to next or previous records, do you know if such properties exiist or another way to move to next or previous records?,
CmbRec.DataSource = dtReceiver
CmbRec.DataTextField = "Name"
CmbRec.DataValueField = "ReceiverID"
CmbRec.DataBind()
CmbDonor.DataSource = dtDonor
CmbDonor.DataTextField = "Name"
CmbDonor.DataValueField = "DonorID"
CmbDonor.DataBind()
ASKER
Thanks!
Val(Subnode1.InnerText) - 1