Probably, it is down to the contents of your text boxes. 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:
com.CommandText = "UPDATE joining SET aname = @NM,fathname=@FN where refno=@RN";
com.Parameters.AddWithValue("@NM", txtName.Text.Trim());
com.Parameters.AddWithValue("@FN", txtFather.Text.Trim());
com.Parameters.AddWithValue("@RN", txtRefNo.Text.Trim());
Not only will your code be better protected, but your problem may well go away as well.