Trying to Insert Values into a Database from TextBoxes
I am totally stumped on this one, and I'm brand new to C# so maybe one of you fine folks can help me out. I'm trying to update a database from form fields using ADO.NET.

Basically, the error I'm getting is that I am trying to insert null values into the database. The exact text of the error is:

    System.ArgumentNullException: The SqlParameterCollection only accepts non-null SqlParameter type objects.

Here is the code behind for the page I am trying to use:

    private void ExecuteInsert(string firstName, string lastName, string emailAddress, string city, string phone)
    {
        SqlConnection conn = new SqlConnection(GetConnectionString());
        string sql = "INSERT INTO contactInfo (firstName, lastName, emailAddress, city, phone) VALUES "
                    + " (@firstName, @lastName, @emailAddress, @city, @phone)";

        try
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlParameter[] param = new SqlParameter[6];
            param[0] = new SqlParameter("@firstName", SqlDbType.NVarChar, 25);
            param[1] = new SqlParameter("@lastName", SqlDbType.NVarChar, 25);
            param[2] = new SqlParameter("@emailAddress", SqlDbType.NVarChar, 30);
            param[3] = new SqlParameter("@city", SqlDbType.NVarChar, 50);
            param[4] = new SqlParameter("@phone", SqlDbType.Int, 10);

            param[0].Value = firstName;
            param[1].Value = lastName;
            param[2].Value = emailAddress;
            param[3].Value = city;
            param[4].Value = phone;

            for (int i = 0; i < param.Length; i++)
            {
                    cmd.Parameters.Add(param[i]);
            }

            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
        }
        catch (System.Data.SqlClient.SqlException ex)
        {
            string msg = "Insert Error:";
            msg += ex.Message;
            throw new Exception(msg);
        }
        finally
        {
            conn.Close();
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (firstName.Text != null)
        {
            //call the method to execute insert to the database
            ExecuteInsert(firstName.Text,
                          lastName.Text,
                          emailAddress.Text,
                          city.Text,
                          phone.Text);
            Response.Write("Record was successfully added!");
            ClearControls(Page);
        }
        else
        {
            Response.Write("Please enter your name");
        }
    }

    public static void ClearControls(Control Parent)
    {

        if (Parent is TextBox)
        { (Parent as TextBox).Text = string.Empty; }
        else
        {
            foreach (Control c in Parent.Controls)
                ClearControls(c);
        }
    }

If there is another way that I should be doing this, I would love to hear it. I just can't seem to find good information online.
Trying to Insert Values into a Database from TextBoxes
===

I am totally stumped on this one, and I'm brand new to C# so maybe one of you fine folks can help me out. I'm trying to update a database from form fields using ADO.NET.

Basically, the error I'm getting is that I am trying to insert null values into the database. The exact text of the error is:

    System.ArgumentNullException: The SqlParameterCollection only accepts non-null SqlParameter type objects.

Here is the code behind for the page I am trying to use:

    private void ExecuteInsert(string firstName, string lastName, string emailAddress, string city, string phone)
    {
        SqlConnection conn = new SqlConnection(GetConnectionString());
        string sql = "INSERT INTO contactInfo (firstName, lastName, emailAddress, city, phone) VALUES "
                    + " (@firstName, @lastName, @emailAddress, @city, @phone)";

        try
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand(sql, conn);
            SqlParameter[] param = new SqlParameter[6];
            param[0] = new SqlParameter("@firstName", SqlDbType.NVarChar, 25);
            param[1] = new SqlParameter("@lastName", SqlDbType.NVarChar, 25);
            param[2] = new SqlParameter("@emailAddress", SqlDbType.NVarChar, 30);
            param[3] = new SqlParameter("@city", SqlDbType.NVarChar, 50);
            param[4] = new SqlParameter("@phone", SqlDbType.Int, 10);

            param[0].Value = firstName;
            param[1].Value = lastName;
            param[2].Value = emailAddress;
            param[3].Value = city;
            param[4].Value = phone;

            for (int i = 0; i < param.Length; i++)
            {
                    cmd.Parameters.Add(param[i]);
            }

            cmd.CommandType = CommandType.Text;
            cmd.ExecuteNonQuery();
        }
        catch (System.Data.SqlClient.SqlException ex)
        {
            string msg = "Insert Error:";
            msg += ex.Message;
            throw new Exception(msg);
        }
        finally
        {
            conn.Close();
        }
    }

    protected void Button1_Click(object sender, EventArgs e)
    {
        if (firstName.Text != null)
        {
            //call the method to execute insert to the database
            ExecuteInsert(firstName.Text,
                          lastName.Text,
                          emailAddress.Text,
                          city.Text,
                          phone.Text);
            Response.Write("Record was successfully added!");
            ClearControls(Page);
        }
        else
        {
            Response.Write("Please enter your name");
        }
    }

    public static void ClearControls(Control Parent)
    {

        if (Parent is TextBox)
        { (Parent as TextBox).Text = string.Empty; }
        else
        {
            foreach (Control c in Parent.Controls)
                ClearControls(c);
        }
    }

If there is another way that I should be doing this, I would love to hear it. I just can't seem to find good information online.