Tuesday 7 February 2012

ProgrammerFail–Advanced techniques using Sql Server in C#

 

[WebMethod]
public static string CreateProfileID(string firstName, string lastName)
{
    string profileID = "";

    using (SqlConnection conn = Common.getConnection())
    {
        try
        {
            conn.Open();
            SqlCommand cmd = new SqlCommand();
            cmd.Connection = conn;
            cmd.CommandType = System.Data.CommandType.Text;
            cmd.CommandText = string.Format("select dbo.[create-something] ('{0}', '{1}') as somethingID", firstName, lastName);

            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                profileID = dr["somethingID"] as string;
            }
        }
        catch (Exception e)
        {

        }
    }

    return profileID;
}

Everything in one method: How to handle exceptions.

 

ProgrammerFail

!!!FAIL!!!

No comments:

Post a Comment