SqlParameter Fails With SqlDbType

Discussion in 'C#' started by SBA-CDeCinko, Aug 28, 2010.

  1. SBA-CDeCinko

    SBA-CDeCinko New Member

    Joined:
    Aug 28, 2010
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    The following function works fine.
    Code:
                     public int AddRecord(String MsgTo, String MsgFrom, String MsgCC, String MsgBC, DateTime DateSent)
                    {
                            SqlParameter[] sqlParams = new SqlParameter[] {
                            new SqlParameter("@MsgTo", MsgTo),
                            new SqlParameter("@MsgFrom", MsgFrom),
                            new SqlParameter("@MsgCC", MsgCC),
                            new SqlParameter("@MsgBC", MsgBC),
                            new SqlParameter("@DateSent", DateSent),
                            };
    
                            return logContactUsMessage.insertMessage(sqlParams);
                    }
    However, when I try and add the dbtype and length, VS2010 says all is ok and compiles, but the code won't run in the browser.  I also cannot find any web examples using this format, even though autocomplete tells me it is correct and valid.
    
                     public int AddRecord(String MsgTo, String MsgFrom, String MsgCC, String MsgBC, DateTime DateSent)
                    {
                            SqlParameter[] sqlParams = new SqlParameter[] {
                            new SqlParameter("@MsgTo", SqlDbType.VarChar, 250, "MsgTo"),
                            new SqlParameter("@MsgFrom", SqlDbType.VarChar, 250, "MsgFrom"),
                            new SqlParameter("@MsgCC", SqlDbType.VarChar, 250, "MsgCC"),
                            new SqlParameter("@MsgBC", SqlDbType.VarChar, 250, "MsgBC"),
                            new SqlParameter("@DateSent", SqlDbType.DateTime, 8, "DateSent"),
                            };
    
                            return logContactUsMessage.insertMessage(sqlParams);
                    }
    
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice