yvrmurari Posted October 22, 2003 Posted October 22, 2003 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 Quote
Administrators PlausiblyDamp Posted October 22, 2003 Administrators Posted October 22, 2003 You could include the call to .ExecuteScalar within a Try / Catch block. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
Moderators Robby Posted October 22, 2003 Moderators Posted October 22, 2003 What does your Select statement look like? Quote Visit...Bassic Software
yvrmurari Posted October 22, 2003 Author Posted October 22, 2003 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.