Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Problem converting SqlDbType.Int to int?
Message
 
 
À
09/07/2008 19:30:18
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
OS:
Windows XP
Database:
Visual FoxPro
Divers
Thread ID:
01330083
Message ID:
01330091
Vues:
25
>Sorry, we're a VB shop now. Just assumed C# would have CInt()
>
>I Don't have C# installed so can't test Maybe
>
>
result = DirectCast(parameters[0], Integer);
>
I was able to pass compiler errors with this code
/// <summary>
    /// Find Person Id from the Name
    /// </summary>
    /// <param name="Name">Person Name Last, First Middle</param>
    /// <param name="DOB">DOB</param> 
    /// <param name="SiteID">SiteID</param>
    /// <returns>ID</returns>    
    public static int? FindPersonID(string Name, DateTime DOB, int? SiteID)
    {
        int? result;
        SqlParameter[] parameters = new SqlParameter[4];
        parameters[0] = new SqlParameter("PersonID", SqlDbType.Int);
        parameters[0].Direction = ParameterDirection.Output;

        parameters[1] = new SqlParameter("FullName", SqlDbType.VarChar, 65);
        parameters[1].Value = Name.Trim(); 
        parameters[2] = new SqlParameter("SiteID", SqlDbType.Int);
        parameters[2].IsNullable = true; 
        parameters[2].Value = SiteID;
        parameters[3] = new SqlParameter("DOB", SqlDbType.DateTime);
        parameters[3].IsNullable = true; 
        parameters[3].Value = DOB; 
                        
        Util.RunStoredProc("FindPersonByName", parameters);
        result = (int?)parameters[0].Value;
        return result;
    }
    /// <summary>
    /// 
    /// </summary>
    /// <param name="Name"></param>
    /// <param name="SiteID"></param>
    /// <returns>ID</returns>
    public static int? FindPersonID(string Name, int? SiteID)
    { return FindPersonID(Name, DateTime.Now.AddYears(50) , SiteID); }
Now I just have to add a check for that invalid DOB and pass null to my SP in this case.

I'm not sure it's the good way of solving this particular problem, but at least I'm not getting these errors anymore (getting new, because I need one more overload).
If it's not broken, fix it until it is.


My Blog
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform