I have this code
SqlCommand objcmd1 = new SqlCommand("select r.login_Id from XYZ where a.logonid = @uId", myADONETConnection);
objcmd1.Parameters.Add("@uId", SqlDbType.VarChar).Value = dr[0].ToString();
returnUserId = (string)objcmd1.ExecuteScalar();
if (returnUserId != null)
{
adid = returnUserId.ToString();
}
else
{
adid = "";
}
I am getting this error. I know that I am getting NULL value as a return value. How do I need to resolve this Issue? Could anybody help me out?
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.InvalidCastException: Unable to cast object of type 'System.DBNull' to type 'System.String'.
at ST_a9849ab5e79d483093f9802cd30cb2e7.csproj.ScriptMain.Main()