Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Dear Reader

I am using ExecuteScalar() to return value from database. It is rerurning error if there are no records.

For Example: For Dept payroll

21031

21032

21033

here 21 is payroll dept code,03 is year and 1,2,3 are the projectid's we can say.

Now say for HR dept with code 20, as there are no records, if i use ExecuteScalar() it is returning error, how to handle that, as there are no records for HR, the first proejctid should be

20031

 

Thanks

Murari

Posted

With select statement

 

Dear Reader

I am using ExecuteScalar() to return value from database. It is rerurning error if there are no records.

For Example: For Dept payroll

21031

21032

21033

here 21 is payroll dept code,03 is year and 1,2,3 are the projectid's we can say.

Now say for HR dept with code 20, as there are no records, if i use ExecuteScalar() it is returning error, how to handle that, as there are no records for HR, the first proejctid should be

20031

 

here is the select statement

Dim cmdINS As New SqlCommand("select max(projectID) from tblprojects where deptname='" & dname & "'", cn)

Dim cnt As Int32 = CInt(cmdINS.ExecuteScalar())

 

Thanks

Murari

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...