MVC 2 Conversion Disrupts the parameters passed to my Stored Procedure

Posted by user54197 on Stack Overflow See other posts from Stack Overflow or by user54197
Published on 2010-04-12T20:07:48Z Indexed on 2010/04/12 20:23 UTC
Read the original article Hit count: 361

Filed under:
|
|

I have a few textboxes that are not required. If the user enters nothing it is passed as 'null' in MVC 2. It was passed as '""' in MVC 1. What changes can I make to accomodate for this?

    public string Name { get; set; }
    public string Offer{ get; set; }
    public string AutoID { get; set; }


        using (SqlConnection connect = new SqlConnection(connections))
        {
            SqlCommand command = new SqlCommand("Info_Add", connect);
            command.Parameters.Add("autoID", SqlDbType.BigInt).Direction = ParameterDirection.Output;                
            command.Parameters.Add(new SqlParameter("name", Name));

            //Offer now returns a null value, which cannot be passed
            command.Parameters.Add(new SqlParameter("offer", Offer));
            command.CommandType = CommandType.StoredProcedure;

            connect.Open();
            command.ExecuteNonQuery();
            AutoID = command.Parameters["autoID"].Value.ToString();
        }

© Stack Overflow or respective owner

Related posts about c#

Related posts about asp.net-mvc