473,404 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,404 software developers and data experts.

Nz not working in VB.NET

VB.net, Microsoft visual studio, ACCESS 2007

Hi,

Im finding the maximum value in a column I have using this sql statment:

Expand|Select|Wrap|Line Numbers
  1. SELECT Nz(Max(TblLeague.rank),0) AS MaxRank 
  2. FROM TblLeague 
  3. WHERE (((TblLeague.sportID)=[sID]));
  4.  
As you can see im using a parameter sID, this just means im looking for the maximum value in that sport.
Im also using the Nz command because when there were no entries for a particular sID a NULL value was being returned as the max value, and i needed this value to actually be 0.

This worked perfectly when the query was run within access.

When i used the below code in VB i got an error:
Undefined function 'Nz' in expression

Expand|Select|Wrap|Line Numbers
  1. Dim MaxRank As Integer
  2.             Dim DataConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & Server.MapPath("App_Data/Database.mdb"))
  3.  
  4.             Dim RankCommand As New OleDbCommand("QryMaxRank")
  5.             RankCommand.CommandType = Data.CommandType.StoredProcedure
  6.             RankCommand.Connection = DataConn
  7.             RankCommand.Parameters.Add(New OleDbParameter("sID", DDLSports.SelectedValue))
  8.  
  9.             DataConn.Open()
  10.             Dim RankDBReader As OleDbDataReader = RankCommand.ExecuteReader()
  11.             MaxRank = RankDBReader("MaxRank")
  12.  
  13.             RankDBReader.Close()
  14.  
Any ideas very welcome, if theres someway to not eliminate the null in sql and deal with it on the vb side of things such as IF null dont do the operation, i would welcome that too.

Thanks
Apr 5 '08 #1
2 5767
shweta123
692 Expert 512MB
Hi,

The another way to not allow the Null values in the database columns is to set the Required field by going into the Design properties of that table. This way you can avoid the Null values at the first place.



VB.net, Microsoft visual studio, ACCESS 2007

Hi,

Im finding the maximum value in a column I have using this sql statment:

Expand|Select|Wrap|Line Numbers
  1. SELECT Nz(Max(TblLeague.rank),0) AS MaxRank 
  2. FROM TblLeague 
  3. WHERE (((TblLeague.sportID)=[sID]));
  4.  
As you can see im using a parameter sID, this just means im looking for the maximum value in that sport.
Im also using the Nz command because when there were no entries for a particular sID a NULL value was being returned as the max value, and i needed this value to actually be 0.

This worked perfectly when the query was run within access.

When i used the below code in VB i got an error:
Undefined function 'Nz' in expression

Expand|Select|Wrap|Line Numbers
  1. Dim MaxRank As Integer
  2.             Dim DataConn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; data source=" & Server.MapPath("App_Data/Database.mdb"))
  3.  
  4.             Dim RankCommand As New OleDbCommand("QryMaxRank")
  5.             RankCommand.CommandType = Data.CommandType.StoredProcedure
  6.             RankCommand.Connection = DataConn
  7.             RankCommand.Parameters.Add(New OleDbParameter("sID", DDLSports.SelectedValue))
  8.  
  9.             DataConn.Open()
  10.             Dim RankDBReader As OleDbDataReader = RankCommand.ExecuteReader()
  11.             MaxRank = RankDBReader("MaxRank")
  12.  
  13.             RankDBReader.Close()
  14.  
Any ideas very welcome, if theres someway to not eliminate the null in sql and deal with it on the vb side of things such as IF null dont do the operation, i would welcome that too.

Thanks
Apr 6 '08 #2
balabaster
797 Expert 512MB
Hi,

The another way to not allow the Null values in the database columns is to set the Required field by going into the Design properties of that table. This way you can avoid the Null values at the first place.
Dim ReturnValue As <DataType> = IIf(Not DataReaderObject("FieldName") = System.DBNull.Value, <TrueValue>, <FalseValue>)

You can obviously substitute TrueValue and FalseValue for whatever data type your data needs to be:

Dim MyVal As Integer = IIf(Not DataReader1("Field1") = System.DBNull.Value, DataReader1("Field1"), 0)

In the event that there's data in Field1 of the DataReader object, it will put that data into MyVal. In the event that the field holds a null value, it will put 0 into MyVal.
Apr 6 '08 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Mullin Yu | last post by:
hi, i have a web service that has file operations on Windows OS, and there may be a file concurrency issue if only one working directory e.g. c:\working therefore, i want to have a unique sub...
5
by: Martin Heuckeroth | last post by:
Hi We are working on a webservice application and are having some problems with the cookies and/or sessions. We have them working on our intranet but then its not working on the internet. We...
5
by: tshad | last post by:
I have been working with setting my drop boxes to allow double clicking to select an item. It worked fine until I made some changes. I then stripped the page down to the bare essentials to find...
8
by: jojobar | last post by:
Okay, I am trying to do is to test the webresource in 2.0 1. I created a new project with assembly name (and default assembly name) "Office". 2. I added the following to the AssemblyInfo.cs...
2
by: Don | last post by:
I'm having problems with intellisense, autocomplete, etc. suddenly not working in certain classes of a project I'm working on. All the options are set, and it all works fine for most classes, but...
9
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
4
by: qbproger | last post by:
I'm developing a plugin for some software. The previous version of the software didn't require a start in directory to be set. This allowed me to leave the working directory to the default in the...
3
by: Jason Huang | last post by:
Hi, In our C# Windows Form application, we are using the SQL Server 2000 as the database server. The Database table MyTable has a field RegistrationDate which represents the Date a client comes...
0
by: WORKING IN FAITH | last post by:
three years I LOVE You Monica More options 1 message - Collapse all WORKING IN FAITH View profile More options Nov 13, 11:29 am three years I LOVE You Monica
3
by: lds | last post by:
On our server we have both applications that have been migrated to use v2.0 of the framework as well as apps that have not yet been migrated and still use 1.1. When I tried to deploy my v2.0 app...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
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,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.