Thursday, March 29, 2012
Please clarify how null nodeset result processes?
sample:
<Station name="Station1" line_stop="yes"/
OR when NO line_stop attribute exists.
In asp.net page, I use xpath to determine IF the line_stop attribute
exists (or am TRYING to!)
Dim xDoc as XmlDocument
Dim xNode As XmlElement =
xDoc.SelectSingleNode("//Station[@dotnet.itags.org.name='Station1'][@dotnet.itags.org.line_stop='yes']")
If Not xNode.Value Is Nothing Then
If xNode.Value = "yes" Then
do this...
End If
End If
If there is no line_stop attribute, I get an error for "Object reference
not set to an instance of an object" at the If Not xNode.Value
line...obviously returning no node.
Please tell me where I'm going wrong.
Thanks,
Kathy
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!Kathy, you might get better responses in the .framework group, since this
doesn't seem to be specific to ASP.NET.
--
John Saunders
Internet Engineer
john.saunders@.surfcontrol.com
"Kathy Burke" <kathyburke40@.attbi.com> wrote in message
news:%23xJL5a0aDHA.2412@.TK2MSFTNGP10.phx.gbl...
> Hi, I continue to have trouble with this. Using the following xml
> sample:
> <Station name="Station1" line_stop="yes"/>
> OR when NO line_stop attribute exists.
> In asp.net page, I use xpath to determine IF the line_stop attribute
> exists (or am TRYING to!)
> Dim xDoc as XmlDocument
> Dim xNode As XmlElement =
> xDoc.SelectSingleNode("//Station[@.name='Station1'][@.line_stop='yes']")
> If Not xNode.Value Is Nothing Then
> If xNode.Value = "yes" Then
> do this...
> End If
> End If
> If there is no line_stop attribute, I get an error for "Object reference
> not set to an instance of an object" at the If Not xNode.Value
> line...obviously returning no node.
> Please tell me where I'm going wrong.
> Thanks,
> Kathy
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
check if the xNode is nothing first
"Kathy Burke" <kathyburke40@.attbi.com> wrote in message
news:%23xJL5a0aDHA.2412@.TK2MSFTNGP10.phx.gbl...
> Hi, I continue to have trouble with this. Using the following xml
> sample:
> <Station name="Station1" line_stop="yes"/>
> OR when NO line_stop attribute exists.
> In asp.net page, I use xpath to determine IF the line_stop attribute
> exists (or am TRYING to!)
> Dim xDoc as XmlDocument
> Dim xNode As XmlElement =
> xDoc.SelectSingleNode("//Station[@.name='Station1'][@.line_stop='yes']")
> If Not xNode.Value Is Nothing Then
> If xNode.Value = "yes" Then
> do this...
> End If
> End If
> If there is no line_stop attribute, I get an error for "Object reference
> not set to an instance of an object" at the If Not xNode.Value
> line...obviously returning no node.
> Please tell me where I'm going wrong.
> Thanks,
> Kathy
> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!
Doesn't "If Not xNode.Value Is Nothing Then" check that xNode is
nothing?
Thanks.
Kathy
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
"Kathy Burke" <kathyburke40@.attbi.com> wrote in message
news:ei17Bx0aDHA.2024@.TK2MSFTNGP12.phx.gbl...
> Doesn't "If Not xNode.Value Is Nothing Then" check that xNode is
> nothing?
No. That checks to see if xNode.Value is Nothing. If xNode is Nothing, the
above "If" statement will throw a NullReferenceException.
To see if xNode is Nothing try:
If Not xNode is Nothing Then
--
John Saunders
Internet Engineer
john.saunders@.surfcontrol.com
Hi again,
I've tried adding:
If Not n16 Is Nothing Then
If n16.Value = "yes" Then
Dim strNext As String = "yes"
End If
End If
but still get a NullReferenceException on the first line of the above
snippet. In this particular case, I SHOULD get "nothing" as a result
since the attribute 'line_stop' doesn't exist for the element
selected...but the code should then continue, yes?
Any suggestions for how I can proceed?
Kathy
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Monday, March 26, 2012
Please help
Any assistance would be very much appreciated. Thanks.
Hmmm, ... where do you execute your command? It seems that you forgot the execution of the command.
Public Sub btnSend_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSend.Click
'Build list of message recipients
Dim dlItem As DataListItem
Dim Recipients As String
For Each dlItem In dtlAssocList.Items
Dim chbSelAssoc As CheckBox = CType(dlItem.FindControl("chbSelAssoc"), CheckBox)
If chbSelAssoc.Checked = True Then
Dim lblAssocCode As Label = CType(dlItem.FindControl("lblAssocCode"), Label)
Recipients += lblAssocCode.Text + ","
End If
Next dlItem'Check to see if the SelectAll checkbox is checked.
Dim SelectAll As String
If chbSelectAll.Checked = True Then
SelectAll = "1"
Else
SelectAll = "0"
End IfDim cnnConnection As System.Data.SqlClient.SqlConnection
Dim connString2 As String = ConfigurationSettings.AppSettings("connString2")
Dim cmdCommand As System.Data.SqlClient.SqlDataAdaptercnnConnection = New System.Data.SqlClient.SqlConnection(connString2)
cmdCommand = New System.Data.SqlClient.SqlDataAdapter("wpsp_MM_I_Message", cnnConnection)cmdCommand.SelectCommand.CommandType = CommandType.StoredProcedure
cmdCommand.SelectCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@dotnet.itags.org.msg_title", SqlDbType.VarChar, 50))
cmdCommand.SelectCommand.Parameters("@dotnet.itags.org.msg_title").Value = txbMsgTitle.Text
cmdCommand.SelectCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@dotnet.itags.org.msg_text", SqlDbType.VarChar, 500))
cmdCommand.SelectCommand.Parameters("@dotnet.itags.org.msg_text").Value = txbMessageText.Text
cmdCommand.SelectCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@dotnet.itags.org.sendAll", SqlDbType.Bit, 1))
cmdCommand.SelectCommand.Parameters("@dotnet.itags.org.sendAll").Value = SelectAll
cmdCommand.SelectCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@dotnet.itags.org.AssocList", SqlDbType.VarChar, 4000))
cmdCommand.SelectCommand.Parameters("@dotnet.itags.org.AssocList").Value = RecipientsResponse.Redirect("ManagersMessage.aspx")
End Sub
You are not aactually doing anything here. You are setting parameters, and then doing nothing. You never open the connection or fill a dataset or anything.
You should debug the application (if using VS.NET) or otherwise, you can use tracing or even Response.Write() to see where you are going.
What are you indending to do?
The 'wpsp_MM_I_Message' Stored Procedure takes the variables that I pass to it and then executes another Stored Procedure (behind the scenes).
What code do I need to include to get the 'wpsp_MM_I_Message' Stored Procedure to execute?
Presuming this returns no records:
Dim cnnConnection As System.Data.SqlClient.SqlConnection
Dim connString2 As String = ConfigurationSettings.AppSettings("connString2")
Dim cmdCommand As System.Data.SqlClient.SqlCommandcnnConnection = New System.Data.SqlClient.SqlConnection(connString2)
cmdCommand = New System.Data.SqlClient.SqlDataAdapter("wpsp_MM_I_Message", cnnConnection)cmdCommand.CommandType = CommandType.StoredProcedure
cmdCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@.msg_title", SqlDbType.VarChar, 50))
cmdCommand.Parameters("@.msg_title").Value = txbMsgTitle.Text
cmdCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@.msg_text", SqlDbType.VarChar, 500))
cmdCommand.Parameters("@.msg_text").Value = txbMessageText.TextcmdCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@.sendAll", SqlDbType.Bit, 1))
cmdCommand.Parameters("@.sendAll").Value = SelectAll
cmdCommand.Parameters.Add(New System.Data.SqlClient.SqlParameter("@.AssocList", SqlDbType.VarChar, 4000))
cmdCommand.Parameters("@.AssocList").Value = RecipientscmdCommand.ExecuteNonQuery()
Note cmdCommand is changed into a SqlCommand object rather than a SqldataAdapter
if it returns records, you could either create a SQLDataReader or a Dataset
That's what I needed. Thank you very much.