Click here to Skip to main content
15,893,594 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here i use code like this
C#
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
Updated 10-Jul-13 20:24pm
v2

Please, use below query:
SQL
select COALESCE(max(ID),0) from tbl_deal where officeid=@officeid

That resolves your problem with DbNull.
 
Share this answer
 
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
 
Share this answer
 
v2
Comments
UDTWS 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
Dholakiya Ankit 11-Jul-13 5:41am    
try like this if (convert.tostring( read.HasValue)=="")
VB
If not read(0)= DBNull.Value Then
a=read(0)
end if 
 
Share this answer
 
Comments
UDTWS 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
VB
if Convert.ToString(read(0))<>"" Then
a=read(0)
else
a=a+1
Endif
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900