Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
Here i use code like this
Dim qry="select max(ID) from tbl_deal where officeid='" & ddl1.SelectedValue.Trim & "'"
dun cmd1 as sqlCommand=New SqlCommand(qry,conn)
conn.open()
dim read As SqlDataReader=cmd1.ExecuteReader()
read.Read()
Dim a=0
if(read.HasValue) Then
a=read(0)
endif
a=a+1
but this code given error in nullvalue its not 1.Thanks
Regards,
Umesh Daiya
Posted 10-Jul-13 21:05pm
UDTWS313
Edited 10-Jul-13 21:24pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Please, use below query:
select COALESCE(max(ID),0) from tbl_deal where officeid=@officeid
That resolves your problem with DbNull.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

give convert.tostring to read(0) if its null then 0 and if its not null then your function a=a+1 and convert read to int if not null ............ convert.tostring can handle null values also it will not throw error
  Permalink  
v2
Comments
UDTWS at 11-Jul-13 5:18am
   
Thanks for reply, i try this code to convert into string in if but error msg Conversion from string "" to type 'Bolean' is not valid
dholakiyaankit at 11-Jul-13 5:41am
   
try like this if (convert.tostring( read.HasValue)=="")
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

If not read(0)= DBNull.Value Then
a=read(0)
end if 
  Permalink  
Comments
UDTWS at 11-Jul-13 5:20am
   
Thanks for reply,
but i got an error msg like this DBNull is a type and cannot be used as an expression
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

if Convert.ToString(read(0))<>"" Then
a=read(0)
else
a=a+1
Endif
  Permalink  

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Mathew Soji 274
1 BillWoodruff 270
2 Afzaal Ahmad Zeeshan 244
3 Sergey Alexandrovich Kryukov 240
4 Raul Iloc 160
0 OriginalGriff 6,219
1 Sergey Alexandrovich Kryukov 5,853
2 DamithSL 5,103
3 Manas Bhardwaj 4,549
4 Maciej Los 3,845


Advertise | Privacy | Mobile
Web04 | 2.8.1411019.1 | Last Updated 11 Jul 2013
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100