The function itself is just returning as void
. But, the point of the posted code is not about what the function is returning. It is the code related to using T-SQL and C# to return data from a SQL database that I would like reviewed. Especially the way the using
statements are structured.
public void GetOffice(int syncID)
{
string strQry = @"
Select so.SyncID,
so.title
From Offices o
Left Outer Join SyncOffices so On so.id = o.SyncID
Where o.SyncID = @syncID
";
using (SqlConnection conn = new SqlConnection(Settings.ConnectionString))
{
using (SqlCommand objCommand = new SqlCommand(strQry, conn))
{
objCommand.CommandType = CommandType.Text;
objCommand.Parameters.AddWithValue("@syncID", syncID);
conn.Open();
SqlDataReader rdr = objCommand.ExecuteReader();
if (rdr.Read())
{
this.OfficeName= rdr.GetString(1);
}
rdr.Close();
}
}
}