‘XPathNavigator' is a type and cannot be used as an expression - InfoPath Dev
in

InfoPath Dev

‘XPathNavigator' is a type and cannot be used as an expression

Last post 11-19-2009 01:24 AM by Kajal Patel. 9 replies.
Page 1 of 1 (10 items)
Sort Posts: Previous Next
  • 11-10-2009 02:42 AM

    ‘XPathNavigator' is a type and cannot be used as an expression

    Hi there,

    I am new to InfoPath and trying to write a code. I tried something simple:

    XPathNavigator root = MainDataSource.CreateNavigator();

    root.SelectSingleNode("/dfs:myFields/dfs:dataFields/d:AOLObservation/d:AOL_Development/@Comments", NamespaceManager).SetValue("Meera Patel");

    But I am getting error message saying:

    ‘XPathNavigator' is a type and cannot be used as an expression

    Could someone please help me????

    Thanks

  • 11-10-2009 04:10 AM In reply to

    Re: ‘XPathNavigator' is a type and cannot be used as an expression

     The code you've posted looks fine the way it is.  Is there possibly some other code you're not showing us?

    Could you also make sure that your form is set to use C# code and not Visual Basic?

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 11-10-2009 04:19 AM In reply to

    Re: ‘XPathNavigator' is a type and cannot be used as an expression

    The form is set to use C# (Under Tools, Options, Design Tab)

    This is the code I have

    Imports Microsoft.Office.InfoPath

    Imports System

    Imports System.Windows.Forms

    Imports System.Xml

    Imports System.Xml.XPath

    Imports mshtml

     

    Namespace AOL2 Public Class FormCode

    Private Sub InternalStartup(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Startup

    AddHandler EventManager.XmlEvents("/dfs:myFields/dfs:dataFields/d:AOLObservation/@ID").Changed, AddressOf AOLObservation_ID_attr_Changed

    AddHandler EventManager.XmlEvents("/dfs:myFields/dfs:dataFields/d:AOLObservation/@ID").Changing, AddressOf AOLObservation_ID_attr_Changing

    AddHandler EventManager.FormEvents.Submit, AddressOf FormEvents_Submit

    AddHandler DirectCast(EventManager.ControlEvents("CTRL162_4"), ButtonEvent).Clicked, AddressOf CTRL162_4_Clicked AddHandler DirectCast(EventManager.ControlEvents("CTRL6_22"), ButtonEvent).Clicked, AddressOf CTRL6_22_Clicked

    End Sub

    Public Sub AOLObservation_ID_attr_Changed(ByVal sender As Object, ByVal e As XmlEventArgs)

    ' Write your code here to change the main data source.

    End Sub

    Public Sub AOLObservation_ID_attr_Changing(ByVal sender As Object, ByVal e As XmlChangingEventArgs)

    ' Ensure that the constraint you are enforcing is compatible

    ' with the default value you set for this XML node.

    ' Write your code here.

    End Sub

     

    Public Sub FormEvents_Submit(ByVal sender As Object, ByVal e As SubmitEventArgs)

    ' If the submit operation is successful, set

    ' e.CancelableArgs.Cancel = False

    ' Write your code here.

    End Sub

    Public Sub CTRL162_4_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

    ' Write your code here.

    End Sub

    Public Sub CTRL6_22_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)

    ' Write your code here.

     

    XPathNavigator root = MainDataSource.CreateNavigator();

    root.SelectSingleNode(
    "/dfs:myFields/dfs:dataFields/d:AOLObservation/d:AOL_Development/@Comments", NamespaceManager).SetValue("Meera Patel");

    End Sub

    End Class

    End Namespace

  • 11-10-2009 04:43 AM In reply to

    Re: ‘XPathNavigator' is a type and cannot be used as an expression

    hi,

    code seems to be good, could you attach the template so that we can have a look at it.

    Qazi Anis
    Technical Architect
    Bitwise Inc
  • 11-10-2009 04:58 AM In reply to

    Re: ‘XPathNavigator' is a type and cannot be used as an expression

    Thanks for helping me out.

    I tried to attach the file but it is 148KB so couldn't.

    Any other option?

  • 11-10-2009 05:26 AM In reply to

    Re: ‘XPathNavigator' is a type and cannot be used as an expression

     That's Visual Basic code, not C#.  Please change the form's programming language to C# in Tools->Form Options->Programming, and add your C# code again.

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 11-10-2009 08:08 AM In reply to

    Re: ‘XPathNavigator' is a type and cannot be used as an expression

    Thanks jimmy

    It is working fine now. I also need some help writing code to add new record to sql table.

    I am not sure where to start from.

     

  • 11-11-2009 03:16 AM In reply to

    Re: ‘XPathNavigator' is a type and cannot be used as an expression

    I have managed to write some code.

    public void Button_Clicked(object sender, ClickedEventArgs e)
            {
                // Write your code here.
                string Id = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/d:AOLObservation/@ID", NamespaceManager).Value;
                string Key = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/d:AOLObservation/d:AOL_Development/@Key", NamespaceManager).Value;
                string Comments = MainDataSource.CreateNavigator().SelectSingleNode("/dfs:myFields/dfs:dataFields/d:AOLObservation/d:AOL_Development/@Comments", NamespaceManager).Value;
               

                SqlConnection MyConnection = new SqlConnection("server=vs-skunk;database=StaffDetails;UID=ework;PWD=ew0rk;");
                SqlCommand command = new SqlCommand(@"INSERT INTO [AOL Development]" + "([AOLID],[Key],[Comments])" + "Values(@Id, @Key, @Comments)",MyConnection);
                try
                {
                    MyConnection.Open();
                    command.ExecuteNonQuery();
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message.ToString());

                }

    }

    But I am getting an error message saying "Must declare the scalar variable "@Id"

    Can you help?????

  • 11-11-2009 04:43 AM In reply to

    Re: ‘XPathNavigator' is a type and cannot be used as an expression

     You need to set values for your three parameters.  Please have a look at this:

    http://www.csharp-station.com/Tutorials/AdoDotNet/lesson06.aspx

    That tutorial adds parameters like this:

    SqlParameter param = new SqlParameter();
    param.ParameterName = "@City";
    param.Value = inputCity;

    cmd.Parameters.Add(param);

    But this whole process can be done with a single command like this:

    cmd.Parameters.AddWithValue("@City", inputCity);

     

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 11-19-2009 01:24 AM In reply to

    Re: ‘XPathNavigator' is a type and cannot be used as an expression

    Thanks for this Jimmy

    I have managed to add a button now. When user clicks on this button the values get added to the database. User can add maximum of 5 records.

    Now my problem is I need to display these values on the form. Any idea how to go around this problem??

     

Page 1 of 1 (10 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.