F
Fredrik Melin
I have some issues with warnings in the new 2005 RTM
For sample, the following code " If Not rsData Is Nothing Then
rsData.Close()"
Gives a warning:
Warning 223 Variable 'rsData' is used before it has been assigned a value. A
null reference exception could result at runtime.
Which is "correct", but what is the correct way to do it?
Dim dbConn As New
SqlClient.SqlConnection(DSO.ConnectionObject.sConnection_String)
Dim cmSQL As New SqlClient.SqlCommand("", dbConn)
Dim rsData As SqlClient.SqlDataReader
Try
dbConn.Open()
cmSQL.Parameters.Add("@NAME", SqlDbType.VarChar).Value = Name
cmSQL.Parameters.Add("@PARENT_ID", SqlDbType.Int).Value =
Parent_ID
cmSQL.CommandText = "INSERT INTO WEBPAGE_GROUPS(NAME, PARENT_ID)
VALUES ( @NAME, @PARENT_ID)"
If cmSQL.ExecuteNonQuery() = 0 Then
Throw New Dacsa_Exceptions.Critical("Failure to add new
group.")
End If
Me.Populate()
Return True
Catch ex As Exception
DSO.Globals.ErrReport.RegisterError(ex, , Me)
Finally
dbConn.Close()
cmSQL.Dispose()
If Not rsData Is Nothing Then rsData.Close()
End Try
Also, This code gives the warning that sPort is a unused local variable
Which I dont understand why...
Dim sPort As String = cInvoice.DSO.Configuration("address label
printer port")
For nCount = 0 To sLabels.GetUpperBound(0)
If IO.File.Exists(Environ("TEMP") & "\Address.txt") Then
IO.File.Delete(Environ("TEMP") & "\Address.txt")
FileOpen(1, Environ("TEMP") & "\Address.txt",
OpenMode.Output)
PrintLine(1, "/#")
PrintLine(1, "FP")
PrintLine(1, "01" & sLabels(nCount))
PrintLine(1, "02" & cInvoice.DSO.Configuration("posten
kundnummer"))
PrintLine(1, "0425")
PrintLine(1, "05" &
cInvoice.Active_ShipTo_Address.sDelivery_Company)
PrintLine(1, "06" &
cInvoice.Active_ShipTo_Address.sStreetAddress)
PrintLine(1, "07" &
Replace(cInvoice.Active_ShipTo_Address.sDelivery_Zip_Code, " ", ""))
PrintLine(1, "08" &
cInvoice.Active_ShipTo_Address.sDelivery_City)
PrintLine(1, "09" & Format(Now, "yyyy-MM-dd"))
If cInvoice.DSO.Configuration("dd_role") = "9" And
cInvoice.nDD_Link_ID > 0 Then
PrintLine(1, "10" &
cInvoice.RemoteConnection.Configuration("company name"))
PrintLine(1, "11" &
cInvoice.RemoteConnection.Configuration("street address"))
PrintLine(1, "12" & "Retur: " &
cInvoice.RemoteInvoice.nOrder_ID)
PrintLine(1, "13" &
Replace(cInvoice.RemoteConnection.Configuration("zip code"), " ", ""))
PrintLine(1, "14" &
cInvoice.RemoteConnection.Configuration("city"))
Else
PrintLine(1, "10" & cInvoice.DSO.Configuration("company
name"))
PrintLine(1, "11" & cInvoice.DSO.Configuration("street
address"))
PrintLine(1, "12" & "Retur: " & cInvoice.nOrder_ID)
PrintLine(1, "13" &
Replace(cInvoice.DSO.Configuration("zip code"), " ", ""))
PrintLine(1, "14" & cInvoice.DSO.Configuration("city"))
End If
PrintLine(1, "/$")
FileClose(1)
IO.File.Copy(Environ("TEMP") & "\Address.txt", sPort)
Next
Return True
For sample, the following code " If Not rsData Is Nothing Then
rsData.Close()"
Gives a warning:
Warning 223 Variable 'rsData' is used before it has been assigned a value. A
null reference exception could result at runtime.
Which is "correct", but what is the correct way to do it?
Dim dbConn As New
SqlClient.SqlConnection(DSO.ConnectionObject.sConnection_String)
Dim cmSQL As New SqlClient.SqlCommand("", dbConn)
Dim rsData As SqlClient.SqlDataReader
Try
dbConn.Open()
cmSQL.Parameters.Add("@NAME", SqlDbType.VarChar).Value = Name
cmSQL.Parameters.Add("@PARENT_ID", SqlDbType.Int).Value =
Parent_ID
cmSQL.CommandText = "INSERT INTO WEBPAGE_GROUPS(NAME, PARENT_ID)
VALUES ( @NAME, @PARENT_ID)"
If cmSQL.ExecuteNonQuery() = 0 Then
Throw New Dacsa_Exceptions.Critical("Failure to add new
group.")
End If
Me.Populate()
Return True
Catch ex As Exception
DSO.Globals.ErrReport.RegisterError(ex, , Me)
Finally
dbConn.Close()
cmSQL.Dispose()
If Not rsData Is Nothing Then rsData.Close()
End Try
Also, This code gives the warning that sPort is a unused local variable
Which I dont understand why...
Dim sPort As String = cInvoice.DSO.Configuration("address label
printer port")
For nCount = 0 To sLabels.GetUpperBound(0)
If IO.File.Exists(Environ("TEMP") & "\Address.txt") Then
IO.File.Delete(Environ("TEMP") & "\Address.txt")
FileOpen(1, Environ("TEMP") & "\Address.txt",
OpenMode.Output)
PrintLine(1, "/#")
PrintLine(1, "FP")
PrintLine(1, "01" & sLabels(nCount))
PrintLine(1, "02" & cInvoice.DSO.Configuration("posten
kundnummer"))
PrintLine(1, "0425")
PrintLine(1, "05" &
cInvoice.Active_ShipTo_Address.sDelivery_Company)
PrintLine(1, "06" &
cInvoice.Active_ShipTo_Address.sStreetAddress)
PrintLine(1, "07" &
Replace(cInvoice.Active_ShipTo_Address.sDelivery_Zip_Code, " ", ""))
PrintLine(1, "08" &
cInvoice.Active_ShipTo_Address.sDelivery_City)
PrintLine(1, "09" & Format(Now, "yyyy-MM-dd"))
If cInvoice.DSO.Configuration("dd_role") = "9" And
cInvoice.nDD_Link_ID > 0 Then
PrintLine(1, "10" &
cInvoice.RemoteConnection.Configuration("company name"))
PrintLine(1, "11" &
cInvoice.RemoteConnection.Configuration("street address"))
PrintLine(1, "12" & "Retur: " &
cInvoice.RemoteInvoice.nOrder_ID)
PrintLine(1, "13" &
Replace(cInvoice.RemoteConnection.Configuration("zip code"), " ", ""))
PrintLine(1, "14" &
cInvoice.RemoteConnection.Configuration("city"))
Else
PrintLine(1, "10" & cInvoice.DSO.Configuration("company
name"))
PrintLine(1, "11" & cInvoice.DSO.Configuration("street
address"))
PrintLine(1, "12" & "Retur: " & cInvoice.nOrder_ID)
PrintLine(1, "13" &
Replace(cInvoice.DSO.Configuration("zip code"), " ", ""))
PrintLine(1, "14" & cInvoice.DSO.Configuration("city"))
End If
PrintLine(1, "/$")
FileClose(1)
IO.File.Copy(Environ("TEMP") & "\Address.txt", sPort)
Next
Return True