|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Null in Visual Basic .Net???the keyword null anymoore in Visual Basic .Net. What can I use instead. SqlConnection connection = null; SqlCommand command = null; SqlDataReader reader = null; String connectionString = "integrated security=SSPI;"; connectionString += "data source=(local);"; connectionString += "initial catalog=Northwind"; String sqlCommandString = "SELECT CustomerID, CompanyName FROM Customers"; try { connection = new SqlConnection(connectionString); command = new SqlCommand(sqlCommandString, connection); connection.Open(); reader = command.ExecuteReader(); if(reader != null) { while(reader.Read()) { Console.Write(reader["CustomerID"]+ "\t"); Console.WriteLine(reader["CompanyName"]); ... } } }catch( ){....} finally { if(reader != null) reader.Close(); if(connection.State == ConnectionState.Open) connection.Close(); } mvh Fia Hi,
If not reader is nothing then Ken ----------------------- Show quoteHide quote "Familjen Karlsson" <fiao***@telia.com> wrote in message news:yifwf.153681$dP1.511961@newsc.telia.net... > How will the code under look like in Visual Basic .Net, since you can't > use > the keyword null anymoore in Visual Basic .Net. What can I use instead. > > SqlConnection connection = null; SqlCommand command = null; SqlDataReader > reader = null; > > String connectionString = "integrated security=SSPI;"; connectionString += > "data source=(local);"; connectionString += "initial catalog=Northwind"; > > String sqlCommandString = "SELECT CustomerID, CompanyName FROM Customers"; > > try { > > connection = new SqlConnection(connectionString); > command = new SqlCommand(sqlCommandString, connection); connection.Open(); > reader = command.ExecuteReader(); > if(reader != null) > { > while(reader.Read()) > { > Console.Write(reader["CustomerID"]+ "\t"); > Console.WriteLine(reader["CompanyName"]); ... > > } > > } > > }catch( ){....} > finally > { > if(reader != null) > reader.Close(); > if(connection.State == ConnectionState.Open) > connection.Close(); > } > > mvh > > Fia > > "Familjen Karlsson" <fiao***@telia.com> schrieb: Visual Basic .NET initializes local variables to 'Nothing' ("null > How will the code under look like in Visual Basic .Net, since you can't > use > the keyword null anymoore in Visual Basic .Net. What can I use instead. > SqlConnection connection = null; SqlCommand command = null; SqlDataReader > reader = null; >[...] > reader = command.ExecuteReader(); > if(reader != null) reference") automatically. Thus you do not need to assign 'Nothing' to these variables explicitly. The line above can be written in VB.NET as shown below: \\\ If Not Reader Is Nothing Then ... End If /// VB 2005 supports the 'IsNot' operator, which can be used to shorten the code to 'If Reader IsNot Nothing Then...'. -- M S Herfried K. Wagner M V P <URL:http://dotnet.mvps.org/> V B <URL:http://classicvb.org/petition/> In VB.Net Null is replaced by DBNull in databases. I had some trouble with
it too a few days ago, so when I solved my problem I wrote an article on it. Here is the link http://cyrilgupta.com/blog/?p=40 Cheers Cyril Gupta Familjen,
You have to distinct a database null value which is a "dbnull.value" and an object which has nothing as address (not instanced) and therefore not referancable, which is than "IS Nothing", Because that address was classical a null value in hardware, is in older types of programming direct that hardware word "null" used for that. I hope this helps, Cor
Printing an ASP.NET web page from VB.NET - (HTTPWebResponse + Printing)
2 keys pressed at once Namespace around API calls Date/Time control Virtual Serial Port Bluetooth System.IO.Ports rotate gdi object Access SubQuery Help Needed..................... Too many case conditions? copying a collection Late Binding syntax problem |
|||||||||||||||||||||||