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.sConn ection_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_Z ip_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("z ip 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 5 1145
I solved the Part 2 of this
Actually had a return statement before the code that always hit, therefor
the sPort isnt used...
"Fredrik Melin" <me*@n.o.spam.dacsa.net.remove.as.needed> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl... 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.sConn ection_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_Z ip_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("z ip 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
You could do this:
Dim rsData As SqlClient.SqlDataReader = Nothing
--
Carsten Thomsen
Communities - http://community.integratedsolutions.dk
"Fredrik Melin" <me*@n.o.spam.dacsa.net.remove.as.needed> wrote in message
news:eH**************@tk2msftngp13.phx.gbl... I solved the Part 2 of this
Actually had a return statement before the code that always hit, therefor the sPort isnt used...
"Fredrik Melin" <me*@n.o.spam.dacsa.net.remove.as.needed> wrote in message news:%2****************@TK2MSFTNGP15.phx.gbl...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.sConn ection_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_Z ip_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("z ip 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
Hi,
I looked at your code and I dont ever see where you use rsData. A
datareader is a forward only way to retrieve records from a database. To
create a datareader you need to use a sqlcommand.executereader. Since you
are adding records to a database you would not get any records back so
executenonquery is the right way to add records. I would just delete the
lines of code with rsData.
Ken
------------
"Fredrik Melin" <me*@n.o.spam.dacsa.net.remove.as.needed> wrote in message
news:eH**************@tk2msftngp13.phx.gbl... I solved the Part 2 of this
Actually had a return statement before the code that always hit, therefor the sPort isnt used...
"Fredrik Melin" <me*@n.o.spam.dacsa.net.remove.as.needed> wrote in message news:%2****************@TK2MSFTNGP15.phx.gbl...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.sConn ection_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_Z ip_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("z ip 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
"CT" <ca******@spammersgoawayintegrasol.dk> schrieb: You could do this:
Dim rsData As SqlClient.SqlDataReader = Nothing
I don't think you should do this in general. If you are doing that in
general it's maybe easier to disable the warning at all and skip explicit
initialization. In VB, as you know, variables get initialized
automatically, so there is absolutely no need for ' = Nothing' from a
technical point of view.
Just my 2 cents...
--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>
Herfried, that is so true, but if you are assignign a value in a code block,
such as a Try...Catch block, I think it makes sense to "disable" the
warning. That's my $0.02 ;-)
--
Carsten Thomsen
Communities - http://community.integratedsolutions.dk
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> wrote in message
news:es****************@TK2MSFTNGP10.phx.gbl... "CT" <ca******@spammersgoawayintegrasol.dk> schrieb: You could do this:
Dim rsData As SqlClient.SqlDataReader = Nothing
I don't think you should do this in general. If you are doing that in general it's maybe easier to disable the warning at all and skip explicit initialization. In VB, as you know, variables get initialized automatically, so there is absolutely no need for ' = Nothing' from a technical point of view.
Just my 2 cents...
-- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Mike Owen |
last post by:
Hi,
I am trying to pre-compile a project prior using ASP.Net 2.0, VS 2005, to
putting it onto a live server.
The reason for doing this is that other people have access to the server,
and I...
|
by: Mart |
last post by:
Hi,
I have just written (my first) VB.net app using MS Visual Basic 2005
Express Edition Beta. It is fairly simple, it reads some configuration
data from an XML file then opens a new window...
|
by: Bob |
last post by:
Hi,
The compiler gives Warning 96 Variable 'cmdSource' is used before it has
been assigned a value. A null reference exception could result at runtime.
Dim cmdSource as SQlClient.SQLDataReader...
|
by: jennifer1970 |
last post by:
Hello. I am trying out the new OneCLick publishing tool that comes
with .Bet 2005 Bets 2. I am getting a lot of warnings and I'm not sure
what they mean or what to do about it. I've got one of...
|
by: Airw0lf |
last post by:
Hi all, would appreciate help with some trouble I'm having after using the
Visual C++ 2005 Express Conversion Wizard on my Visual C++ .NET 2003
project.
The wizard completed successfully with...
| |
by: Crazy Cat |
last post by:
Hi,
I'm developing an application that is basically a VB.NET front end to a
SQL Server Express 2005 database -- right now I'm using VB.NET 2005
Express until my MSDN subscription gets delivered...
|
by: Agnes |
last post by:
Very painful !!
my application run in 2003 is very well, (except General network error)
Now, as i complie by 2005, many error occured,
se.g combox's select index .2005 find me many many logicial...
|
by: John Dann |
last post by:
Just getting started with VB2005 and unsure how best to move active
VB2003 projects into the VB2005 environment.
Nornally I've versioned my VB2003 projects at specific development
points by...
|
by: hsmit.home |
last post by:
I spent way too much time on this and I must say, I was a little
disgruntled with what has been posted on all the various Xalan C
mailing lists. Everyone says there's a solution, but give next to...
|
by: tesis |
last post by:
Hi all gurus,
I'm trying to convert an ASP.NET (2003) project into 2005. It uses C1
components and CR11.5V2, which model is NOT CLS-compliant. This
generates several warnings, blocking...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
| |
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
|
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...
| |