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
UDTWS316
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 Sergey Alexandrovich Kryukov 555
1 Kornfeld Eliyahu Peter 409
2 Maciej Los 359
3 DamithSL 196
4 OriginalGriff 188
0 OriginalGriff 6,353
1 DamithSL 4,854
2 Maciej Los 4,466
3 Kornfeld Eliyahu Peter 4,058
4 Sergey Alexandrovich Kryukov 3,897


Advertise | Privacy | Mobile
Web03 | 2.8.141220.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