Please, do not do it like that! Do not concatenate strings to build a SQL command. It leaves you wide open to accidental or deliberate SQL Injection attack which can destroy your entire database. Use Parametrized queries instead.
Secondly, the easiest way to do that is to use a single command:
using (SqlConnection con = new SqlConnection(strConnect))
{
con.Open();
using (SqlCommand com = new SqlCommand("INSERT INTO MyTable (myColumn1, myColumn2) VALUES ('XXX', 666) SELECT SCOPE_IDENTITY()", con))
{
decimal d = (decimal) com.ExecuteScalar();
}
}
d
will contain the ID you just assigned.